/** * @test */ public function writesToStandardOutputBuffer() { $out = new StandardOutputStream(); ob_start(); $out->write('foo'); assert(ob_get_contents(), equals('foo')); ob_end_clean(); }
/** * @test */ public function canIterateOverNonSeekableInputStream() { $inputStream = NewInstance::of(InputStream::class)->mapCalls(['readLine' => onConsecutiveCalls('foo', 'bar', 'baz', ''), 'eof' => onConsecutiveCalls(false, false, false, true)]); $content = []; foreach (linesOf($inputStream) as $lineNumber => $line) { $content[$lineNumber] = $line; } assert($content, equals([1 => 'foo', 2 => 'bar', 3 => 'baz'])); }
/** * @test */ public function keyConsumerIsNotCalledWhenNoKeyInForeachRequested() { $i = 0; $peek = new Peek(new \ArrayIterator(['foo' => 303, 'bar' => 404, 'baz' => 505]), function () { }, function () { fail('Key consumer is not expected to be called'); }); foreach ($peek as $value) { $i++; } assert($i, equals(3)); }
/** * @test */ public function infiniteGeneratorDoesStopOnlyWhenBreakOutOfLoop() { $i = 0; foreach (Generator::infinite(0, function ($value) { return $value + 2; }) as $key => $value) { if (1000 > $key) { $i++; } else { break; } } assert($i, equals(1000)); }
/** * @test */ public function parseRecognizesHttpsUris() { assert(Parse::toType('https://example.net/'), equals(HttpUri::fromString('https://example.net/'))); }
/** * @test */ public function handleSignalsResultOfResponsibleErrorHandlerIfErrorReportingEnabled() { $oldLevel = error_reporting(E_ALL); try { $this->errorHandler1->mapCalls(['isResponsible' => false]); $this->errorHandler2->mapCalls(['isResponsible' => true, 'isSupressable' => false, 'handle' => ErrorHandler::STOP_ERROR_HANDLING]); assert($this->errorHandlers->handle(1, 'foo'), equals(ErrorHandler::STOP_ERROR_HANDLING)); } finally { error_reporting($oldLevel); } }
/** * @test * @since 3.2.0 */ public function writeLinesWritesBytesIntoBuffer() { $this->memoryOutputStream->writeLines(['hello', 'world']); assert($this->memoryOutputStream->buffer(), equals("hello\nworld\n")); }
/** * @param mixed $value * @param string $expectedType * @test * @dataProvider valueTypes * @since 7.0.0 */ public function typeOfOtherValuesReturnsNativeType($value, string $expectedType) { assert(typeOf($value), equals($expectedType)); }
/** * @since 2.0.0 * @test */ public function deleteWritesCorrectRequestWithVersion() { $this->createHttpRequest()->delete(5, HttpVersion::HTTP_1_0); assert($this->memory, equals(Http::lines('DELETE /foo/resource HTTP/1.0', 'Host: example.com', 'X-Binford: 6100', ''))); }
/** * @test * @since 4.1.0 */ public function returnsParsedValuesForCommonProperties() { assert($this->createPropertyBinding('DEV')->getInstance($this->injector, 'baz'), equals(reflect(Properties::class))); }
/** * @test */ public function bytesLeftCallsDecoratedStream() { assert($this->decoratedInputStream->bytesLeft(), equals(4)); }
/** * @test * @since 3.2.0 */ public function writeLinesPassesBytesWithLinebreakIntoStream() { $file = vfsStream::newFile('test.txt')->at($this->root); $resourceOutputStream = $this->createResourceOutputStream(fopen(vfsStream::url('root/test.txt'), 'w')); assert($resourceOutputStream->writeLines(['foo', 'bar', 'baz']), equals(15)); assert($file->getContent(), equals("foo\r\nbar\r\nbaz\r\n")); }
/** * @test */ public function partitioningByWithSum() { assert(Sequence::of($this->people)->collect()->inPartitions(function (Employee $e) { return $e->years() > 10; }, Collector::forSum(function (Employee $e) { return $e->years(); })), equals([true => 29, false => 4])); }
/** * @test * @since 8.0.0 */ public function startsAtPositionZero() { assert($this->standardInputStream->tell(), equals(0)); }
/** * @test * @since 7.0.0 */ public function headerListCanBeCastedToString() { $headers = "Binford: 6100\r\nX-Power: More power!"; assert((string) parseHeaders($headers), equals($headers)); }
/** * @test */ public function createInputStreamUsesGivenStringAsStreamContent() { $memoryInputStream = $this->memoryStreamFactory->createInputStream('buffer'); assert($memoryInputStream->readLine(), equals('buffer')); }
/** * @test */ public function exportsAnyThingElseWithDefault() { assert(Provides::values([1])->describeValue(exporter(), 'foo'), equals('\'foo\'')); }
/** * @test */ public function mixedAnnotations() { $plugin = NewInstance::of(Plugin::class); $binder = new Binder(); $binder->bindList('listConfig'); $binder->bindMap('mapConfig'); $binder->bind(Plugin::class)->named('foo')->toInstance($plugin); $binder->bindConstant('foo')->to(42); $binder->bindList('aList')->withValue(313); $binder->bindMap('aMap')->withEntry('tb', 303); assert($this->createPluginHandler($binder)->getArgs(), equals(['std' => $plugin, 'answer' => 42, 'list' => [313], 'map' => ['tb' => 303]])); }
/** * @test */ public function namedConstructorInjectionWithMultipleParamAndNamedParamGroup() { $binder = new Binder(); $binder->bind(Employee::class)->named('schst')->to(Boss::class); $binder->bind(Employee::class)->to(TeamMember::class); $injector = $binder->getInjector(); $group = $injector->getInstance(DevelopersMultipleConstructorParamsGroupedName::class); assert($group, equals(new DevelopersMultipleConstructorParamsGroupedName(new Boss(), new Boss()))); }
/** * @test * @since 8.0.0 */ public function writeLinesReturnsOnlyAmountOfUnfilteredBytedWritten() { assert($this->filteredOutputStream->writeLines(['foo', 'bar']), equals(4)); }
/** * @test */ public function toMapPassesKeyAndValueWhenNoSelectorProvided() { assert(Sequence::of($this->people)->collect()->inMap(), equals($this->people)); }
/** * @test */ public function writesToResource() { assert($this->stream->write('yoyoyoyo'), equals(8)); assert($this->file->getContent(), equals('yoyoyoyo')); }
/** * @test * @dataProvider throwables */ public function createsLogDirectoryWithChangedModeIfNotExists($throwable) { $this->exceptionLogger->setFilemode(0777)->log($throwable); assert($this->root->getChild(self::$logPath)->getPermissions(), equals(0777)); }
/** * Assert that a purge request was received. * * @Then the web front end cache was instructed to purge certain paths for the application tag :arg1 */ public function theWebFrontEndCacheWasInstructedToPurgeCertainPaths($arg1) { $requests = $this->getRequests(); assert($requests, isOfSize(1)); $purge_request = $requests->last(); assert($purge_request->getHeader('X-Invalidate-Tag')->toArray(), equals([$arg1])); assert($purge_request->getHeader('X-Invalidate-Type')->toArray(), equals(['regexp-multiple'])); }
/** * @test */ public function castFromStringReturnsInstance() { assert(HttpVersion::castFrom('HTTP/1.1'), equals(new HttpVersion(1, 1))); }
/** * @test * @since 3.2.0 */ public function writeLinesEncodesBytesBeforePassedToDecoratedStream() { assert($this->encodingOutputStream->writeLines(['hällö', 'wörld']), equals(12)); assert($this->memory->buffer(), equals(utf8_decode("hällö\nwörld\n"))); }
/** * @test * @group ioc_constantprovider * @since 1.6.0 */ public function constantViaInjectionProviderClassName() { $binder = new Binder(); $binder->bindConstant('answer')->toProviderClass(AnswerConstantProvider::class); $injector = $binder->getInjector(); assertTrue($injector->hasConstant('answer')); assert($injector->getConstant('answer'), equals(42)); $this->assertConstantInjection($binder->getInjector()); }
/** * @since 2.0.0 * @test */ public function deleteWritesProperHttpRequestLines() { $this->httpConnection->timeout(2)->asUserAgent('Stubbles HTTP Client')->referedFrom('http://example.com/')->withCookie(['foo' => 'bar baz'])->authorizedAs('user', 'pass')->usingHeader('X-Binford', 6100)->delete(); assert($this->memory, equals(Http::lines('DELETE /foo/resource HTTP/1.1', 'Host: example.com', 'User-Agent: Stubbles HTTP Client', 'Referer: http://example.com/', 'Cookie: foo=bar+baz;', 'Authorization: BASIC ' . base64_encode('user:pass'), 'X-Binford: 6100', ''))); }
/** * @test */ public function setsCorrectPropertiesInRuntimeModeWithDefaultProperties() { $propertyReceiver = $this->createInjector('DEV')->getInstance(PropertyReceiver::class); assert($propertyReceiver->foo, equals('default')); assert($propertyReceiver->bar, equals('someValue')); }
/** * * @param mixed $expected * @param string $method * @test * @dataProvider methods * @since 5.0.0 */ public function parseNullWithDefaultReturnsDefault($expected, string $method) { $parse = new Parse(null); assert($parse->defaultingTo('foo')->{$method}(), equals('foo')); }