diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index fcfaba9c..7d27dc07 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -4,20 +4,24 @@ on: # yamllint disable-line rule:truthy pull_request: paths: - 'src/**' - - 'tests/**' - 'bin/trap' - '.php-cs-fixer.dist.php' + - 'psalm*' + - 'phpstan*' + - 'composer.*' push: paths: - 'src/**' - - 'tests/**' - 'bin/trap' - '.php-cs-fixer.dist.php' + - 'psalm*' + - 'phpstan*' + - 'composer.*' name: 🔍 Static analysis jobs: - static-analysis: + psalm: timeout-minutes: 4 runs-on: ${{ matrix.os }} concurrency: @@ -68,5 +72,53 @@ jobs: - name: 🔍 Run static analysis using vimeo/psalm run: composer psalm:ci + phpstan: + timeout-minutes: 4 + runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: static-analysis-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + strategy: + fail-fast: true + matrix: + os: + - ubuntu-latest + php-version: + - '8.2' + dependencies: + - locked + steps: + - name: 📦 Check out the codebase + uses: actions/checkout@v4.1.5 + + - name: 🛠️ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets, opcache, pcntl, posix + ini-values: error_reporting=E_ALL + coverage: none + + - name: 🛠️ Setup problem matchers + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: 🤖 Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: 🔍 Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: ♻️ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: 📥 Install "${{ matrix.dependencies }}" dependencies + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + - name: 🔍 Run static analysis using phpstan/phpstan run: composer stan:ci diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c5c30362..d03a4e43 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,6 +6,8 @@ parameters: paths: - bin/ - src/ - - tests/ - .php-cs-fixer.dist.php + excludePaths: + analyse: + - src/Test/Proto/ tmpDir: .build/phpstan/ diff --git a/tests/Unit/Client/FunctionTrapTest.php b/tests/Unit/Client/FunctionTrapTest.php index e3cd7399..51c51196 100644 --- a/tests/Unit/Client/FunctionTrapTest.php +++ b/tests/Unit/Client/FunctionTrapTest.php @@ -20,6 +20,6 @@ public function testLeak(): void trap($object, $object); unset($object); - $this->assertNull($ref->get()); + self::assertNull($ref->get()); } } diff --git a/tests/Unit/Client/TrTest.php b/tests/Unit/Client/TrTest.php index 5bb22e03..0ce8b85b 100644 --- a/tests/Unit/Client/TrTest.php +++ b/tests/Unit/Client/TrTest.php @@ -51,27 +51,27 @@ public function testLeak(): void tr($object, $object); unset($object); - $this->assertNull($ref->get()); + self::assertNull($ref->get()); } public function testReturn(): void { - $this->assertSame(42, tr(42)); - $this->assertSame(42, tr(named: 42)); - $this->assertSame(42, tr(42, 43)); - $this->assertSame('foo', tr(...['0' => 'foo', 42 => 90])); - $this->assertNull(tr(null)); + self::assertSame(42, tr(42)); + self::assertSame(42, tr(named: 42)); + self::assertSame(42, tr(42, 43)); + self::assertSame('foo', tr(...['0' => 'foo', 42 => 90])); + self::assertNull(tr(null)); } public function testReturnSendsDumpOnce(): void { $dumper = $this->getMockBuilder(DataDumperInterface::class) ->getMock(); - $dumper->expects($this->once()) + $dumper->expects(self::once()) ->method('dump') ->willReturnArgument(1); Dumper::setDumper($dumper); - $this->assertSame(42, tr(42)); + self::assertSame(42, tr(42)); } } diff --git a/tests/Unit/Client/TrapTest.php b/tests/Unit/Client/TrapTest.php index 52ac0740..da5d914b 100644 --- a/tests/Unit/Client/TrapTest.php +++ b/tests/Unit/Client/TrapTest.php @@ -20,7 +20,7 @@ public static function provideTrapTimes(): iterable public function testLabel(): void { trap(FooName: 'foo-value'); - $this->assertSame('FooName', self::$lastData->getContext()['label']); + self::assertSame('FooName', self::$lastData->getContext()['label']); } public function testSimpleContext(): void @@ -61,11 +61,11 @@ public function testStackTrace(): void { $line = __FILE__ . ':' . __LINE__ and trap()->stackTrace(); - $this->assertArrayHasKey('trace', self::$lastData->getValue()); + self::assertArrayHasKey('trace', self::$lastData->getValue()); $neededLine = \array_key_first(self::$lastData->getValue()['trace']->getValue()); - $this->assertStringContainsString($line, $neededLine); + self::assertStringContainsString($line, $neededLine); } /** @@ -89,7 +89,7 @@ public function testLeak(): void trap($object, $object); unset($object); - $this->assertNull($ref->get()); + self::assertNull($ref->get()); } public function testTrapOnce(): void @@ -103,29 +103,29 @@ public function testTrapOnce(): void public function testReturn(): void { - $this->assertSame(42, trap(42)->return()); - $this->assertSame(42, trap(named: 42)->return()); - $this->assertSame(42, trap(named: 42)->return('bad-name')); - $this->assertSame(42, trap(42, 43)->return()); - $this->assertSame(42, trap(int: 42, foo: 'bar')->return('int')); - $this->assertSame(42, trap(int: 42, foo: 'bar')->return(0)); - $this->assertSame('foo', trap(...['0' => 'foo', 42 => 90])->return()); - $this->assertNull(trap(null)->return()); - - $this->expectException(\InvalidArgumentException::class); - $this->assertSame(42, trap(42, 43)->return(10)); + self::assertSame(42, trap(42)->return()); + self::assertSame(42, trap(named: 42)->return()); + self::assertSame(42, trap(named: 42)->return('bad-name')); + self::assertSame(42, trap(42, 43)->return()); + self::assertSame(42, trap(int: 42, foo: 'bar')->return('int')); + self::assertSame(42, trap(int: 42, foo: 'bar')->return(0)); + self::assertSame('foo', trap(...['0' => 'foo', 42 => 90])->return()); + self::assertNull(trap(null)->return()); + + self::expectException(\InvalidArgumentException::class); + self::assertSame(42, trap(42, 43)->return(10)); } public function testReturnSendsDumpOnce(): void { $dumper = $this->getMockBuilder(DataDumperInterface::class) ->getMock(); - $dumper->expects($this->once()) + $dumper->expects(self::once()) ->method('dump') ->willReturnArgument(1); Dumper::setDumper($dumper); - $this->assertSame(42, trap(42)->return()); + self::assertSame(42, trap(42)->return()); } /** diff --git a/tests/Unit/Handler/Router/RouterTest.php b/tests/Unit/Handler/Router/RouterTest.php index 67090e65..8050ffe2 100644 --- a/tests/Unit/Handler/Router/RouterTest.php +++ b/tests/Unit/Handler/Router/RouterTest.php @@ -62,7 +62,7 @@ public function testRouteAssertions(string $class): void ); Router::assert($routes, $asserts); - $this->assertTrue(true, (string) $method . ' passed'); + self::assertTrue(true, (string) $method . ' passed'); } } @@ -70,47 +70,47 @@ public function testTryPrivate(): void { $router = Router::new(self::class); - $this->assertNotNull($router->match(Method::Get, '/private-route')); + self::assertNotNull($router->match(Method::Get, '/private-route')); } public function testMatchPublicStaticRoute(): void { $router = Router::new($this); - $this->assertNotNull($route = $router->match(Method::Get, '/public-static-route')); - $this->assertSame('public-static-route-result', $route()); + self::assertNotNull($route = $router->match(Method::Get, '/public-static-route')); + self::assertSame('public-static-route-result', $route()); } public function testMatchPublicStaticStaticRoute(): void { $router = Router::new(self::class); - $this->assertNotNull($route = $router->match(Method::Get, '/public-static-static-route')); - $this->assertSame('public-static-static-route-result', $route()); + self::assertNotNull($route = $router->match(Method::Get, '/public-static-static-route')); + self::assertSame('public-static-static-route-result', $route()); } public function testMatchPublicStaticRegexpRoute(): void { $router = Router::new(self::class); - $this->assertNotNull($route = $router->match(Method::Delete, '/item/123e4567-e89b-12d3-a456-426614174000')); - $this->assertSame('123e4567-e89b-12d3-a456-426614174000', $route()); + self::assertNotNull($route = $router->match(Method::Delete, '/item/123e4567-e89b-12d3-a456-426614174000')); + self::assertSame('123e4567-e89b-12d3-a456-426614174000', $route()); } public function testMatchPublicStaticRegexpRouteWithAdditionalArgs(): void { $router = Router::new(self::class); - $this->assertNotNull($route = $router->match(Method::Delete, '/item/123e4567-e89b-12d3-a456-426614174000')); - $this->assertSame('123e4567-e89b-12d3-a456-426614174000', $route(id: 'test')); + self::assertNotNull($route = $router->match(Method::Delete, '/item/123e4567-e89b-12d3-a456-426614174000')); + self::assertSame('123e4567-e89b-12d3-a456-426614174000', $route(id: 'test')); } public function testArgumentsCollision(): void { $router = Router::new(self::class); - $this->assertNotNull($route = $router->match(Method::Delete, '/item/123e4567-e89b-12d3-a456-426614174000')); - $this->assertSame('123e4567-e89b-12d3-a456-426614174000', $route(uuid: 'no-pasaran')); + self::assertNotNull($route = $router->match(Method::Delete, '/item/123e4567-e89b-12d3-a456-426614174000')); + self::assertSame('123e4567-e89b-12d3-a456-426614174000', $route(uuid: 'no-pasaran')); } #[StaticRoute(Method::Get, '/public-static-route')] diff --git a/tests/Unit/Sender/Frontend/EventsStorageTest.php b/tests/Unit/Sender/Frontend/EventsStorageTest.php index dabb22da..afa60b54 100644 --- a/tests/Unit/Sender/Frontend/EventsStorageTest.php +++ b/tests/Unit/Sender/Frontend/EventsStorageTest.php @@ -22,11 +22,11 @@ public function testMaxEventsLimit(): void $storage->add($e2 = $this->createEvent()); $storage->add($e3 = $this->createEvent()); - $this->assertCount(2, $storage); + self::assertCount(2, $storage); // In an ordered event sequence of adding events, the first event should be removed - $this->assertNull($storage->get($e1->uuid)); - $this->assertNotNull($storage->get($e2->uuid)); - $this->assertNotNull($storage->get($e3->uuid)); + self::assertNull($storage->get($e1->uuid)); + self::assertNotNull($storage->get($e2->uuid)); + self::assertNotNull($storage->get($e3->uuid)); } public function testMaxEventsLimitWithSort(): void @@ -39,15 +39,15 @@ public function testMaxEventsLimitWithSort(): void $storage->add($e2 = $this->createEvent()); $storage->add($e3 = $this->createEvent(timestamp: \microtime(true) - 1)); - $this->assertCount(2, $storage); + self::assertCount(2, $storage); // new event should be added in order of timestamp, and then the first event should be removed - $this->assertNull($storage->get($e3->uuid)); - $this->assertNotNull($storage->get($e1->uuid)); - $this->assertNotNull($storage->get($e2->uuid)); + self::assertNull($storage->get($e3->uuid)); + self::assertNotNull($storage->get($e1->uuid)); + self::assertNotNull($storage->get($e2->uuid)); // Check order of events $events = \iterator_to_array($storage->getIterator(), false); - $this->assertSame($e2->uuid, $events[0]->uuid); - $this->assertSame($e1->uuid, $events[1]->uuid); + self::assertSame($e2->uuid, $events[0]->uuid); + self::assertSame($e1->uuid, $events[1]->uuid); } private function createEvent( diff --git a/tests/Unit/Traffic/Dispatcher/HttpTest.php b/tests/Unit/Traffic/Dispatcher/HttpTest.php index bda28112..58ef6f34 100644 --- a/tests/Unit/Traffic/Dispatcher/HttpTest.php +++ b/tests/Unit/Traffic/Dispatcher/HttpTest.php @@ -54,6 +54,6 @@ public static function detectProvider() public function testDetect(string $data, ?bool $expected): void { $dispatcher = new Http(); - $this->assertSame($expected, $dispatcher->detect($data, new \DateTimeImmutable())); + self::assertSame($expected, $dispatcher->detect($data, new \DateTimeImmutable())); } } diff --git a/tests/Unit/Traffic/Dispatcher/VarDumperTest.php b/tests/Unit/Traffic/Dispatcher/VarDumperTest.php index 9ccb3a11..495a972d 100644 --- a/tests/Unit/Traffic/Dispatcher/VarDumperTest.php +++ b/tests/Unit/Traffic/Dispatcher/VarDumperTest.php @@ -28,7 +28,7 @@ public static function detectProvider(): iterable public function testDetect(string $data, ?bool $expected): void { $dispatcher = new VarDumper(); - $this->assertSame($expected, $dispatcher->detect($data, new \DateTimeImmutable())); + self::assertSame($expected, $dispatcher->detect($data, new \DateTimeImmutable())); } public function testDispatchFramesTime(): void diff --git a/tests/Unit/Traffic/Emitter/HttpTest.php b/tests/Unit/Traffic/Emitter/HttpTest.php index 7f1d1d4e..54811027 100644 --- a/tests/Unit/Traffic/Emitter/HttpTest.php +++ b/tests/Unit/Traffic/Emitter/HttpTest.php @@ -59,8 +59,8 @@ static function () use ($response, $stream2): void { } // Check that the data is the same - $this->assertSame($data1, $data2); - $this->assertSame($content, $data1); - $this->assertSame($content, $data2); + self::assertSame($data1, $data2); + self::assertSame($content, $data1); + self::assertSame($content, $data2); } } diff --git a/tests/Unit/Traffic/Message/Multipart/FieldTest.php b/tests/Unit/Traffic/Message/Multipart/FieldTest.php index b8cf99ed..33352c6d 100644 --- a/tests/Unit/Traffic/Message/Multipart/FieldTest.php +++ b/tests/Unit/Traffic/Message/Multipart/FieldTest.php @@ -13,9 +13,9 @@ public function testGetters(): void { $field = new Field(['Foo' => 'Bar'], 'name', 'value'); - $this->assertSame('name', $field->getName()); - $this->assertSame('value', $field->getValue()); - $this->assertSame('Bar', $field->getHeaderLine('foo')); + self::assertSame('name', $field->getName()); + self::assertSame('value', $field->getValue()); + self::assertSame('Bar', $field->getHeaderLine('foo')); } public function testWithHeader(): void @@ -23,18 +23,18 @@ public function testWithHeader(): void $field = new Field(['Foo' => 'Bar'], 'name', 'value'); $new = $field->withHeader('foo', 'baz'); - $this->assertNotSame($field, $new); - $this->assertSame('Bar', $field->getHeaderLine('foo')); - $this->assertSame('baz', $new->getHeaderLine('foo')); + self::assertNotSame($field, $new); + self::assertSame('Bar', $field->getHeaderLine('foo')); + self::assertSame('baz', $new->getHeaderLine('foo')); } public function testFromArray(): void { $field = Field::fromArray(['headers' => ['Foo' => ['Bar', 'Baz']], 'value' => 'bar']); - $this->assertNull($field->getName()); - $this->assertSame('bar', $field->getValue()); - $this->assertSame(['Bar', 'Baz'], $field->getHeader('foo')); + self::assertNull($field->getName()); + self::assertSame('bar', $field->getValue()); + self::assertSame(['Bar', 'Baz'], $field->getHeader('foo')); } public function testSerializeAndUnserialize(): void @@ -42,6 +42,6 @@ public function testSerializeAndUnserialize(): void $from = new Field(['Foo' => ['Bar', 'Baz']], 'message', 'foo bar baz'); $to = Field::fromArray($from->jsonSerialize()); - $this->assertEquals($from, $to); + self::assertEquals($from, $to); } } diff --git a/tests/Unit/Traffic/Message/Multipart/FileTest.php b/tests/Unit/Traffic/Message/Multipart/FileTest.php index 5f565e63..c9bf9992 100644 --- a/tests/Unit/Traffic/Message/Multipart/FileTest.php +++ b/tests/Unit/Traffic/Message/Multipart/FileTest.php @@ -14,9 +14,9 @@ public function testGetters(): void { $file = new File(['Foo' => 'Bar'], 'name', 'filename'); - $this->assertSame('name', $file->getName()); - $this->assertSame('filename', $file->getClientFilename()); - $this->assertSame('Bar', $file->getHeaderLine('foo')); + self::assertSame('name', $file->getName()); + self::assertSame('filename', $file->getClientFilename()); + self::assertSame('Bar', $file->getHeaderLine('foo')); } public function testWithHeader(): void @@ -24,9 +24,9 @@ public function testWithHeader(): void $file = new File(['Foo' => 'Bar'], 'name', 'filename'); $new = $file->withHeader('foo', 'baz'); - $this->assertNotSame($file, $new); - $this->assertSame('Bar', $file->getHeaderLine('foo')); - $this->assertSame('baz', $new->getHeaderLine('foo')); + self::assertNotSame($file, $new); + self::assertSame('Bar', $file->getHeaderLine('foo')); + self::assertSame('baz', $new->getHeaderLine('foo')); } public function testFromArray(): void @@ -37,11 +37,11 @@ public function testFromArray(): void 'size' => 10, ]); - $this->assertNull($field->getName()); - $this->assertSame(10, $field->getSize()); - $this->assertSame('bar.jpg', $field->getClientFilename()); - $this->assertSame('image/jpeg', $field->getClientMediaType()); - $this->assertSame(['Bar', 'Baz'], $field->getHeader('foo')); + self::assertNull($field->getName()); + self::assertSame(10, $field->getSize()); + self::assertSame('bar.jpg', $field->getClientFilename()); + self::assertSame('image/jpeg', $field->getClientMediaType()); + self::assertSame(['Bar', 'Baz'], $field->getHeader('foo')); } public function testSerializeAndUnserialize(): void @@ -53,9 +53,9 @@ public function testSerializeAndUnserialize(): void $to = File::fromArray($from->jsonSerialize()); - $this->assertSame($from->getHeaders(), $to->getHeaders()); - $this->assertSame($from->getSize(), $to->getSize()); - $this->assertSame($from->getClientFilename(), $to->getClientFilename()); - $this->assertSame($from->getClientMediaType(), $to->getClientMediaType()); + self::assertSame($from->getHeaders(), $to->getHeaders()); + self::assertSame($from->getSize(), $to->getSize()); + self::assertSame($from->getClientFilename(), $to->getClientFilename()); + self::assertSame($from->getClientMediaType(), $to->getClientMediaType()); } } diff --git a/tests/Unit/Traffic/Parser/HttpParserTest.php b/tests/Unit/Traffic/Parser/HttpParserTest.php index aa562d71..fbc27293 100644 --- a/tests/Unit/Traffic/Parser/HttpParserTest.php +++ b/tests/Unit/Traffic/Parser/HttpParserTest.php @@ -39,12 +39,12 @@ public function testSimpleGet(): void $request = $this->parseStream($body); - $this->assertSame('GET', $request->getMethod()); - $this->assertSame('/foo/bar', $request->getUri()->getPath()); - $this->assertSame('1.1', $request->getProtocolVersion()); - $this->assertSame(['127.0.0.1:9912'], $request->getHeader('host')); - $this->assertSame(['ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3'], $request->getHeader('accept-language')); - $this->assertSame([ + self::assertSame('GET', $request->getMethod()); + self::assertSame('/foo/bar', $request->getUri()->getPath()); + self::assertSame('1.1', $request->getProtocolVersion()); + self::assertSame(['127.0.0.1:9912'], $request->getHeader('host')); + self::assertSame(['ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3'], $request->getHeader('accept-language')); + self::assertSame([ 'koa.sess' => 'Ijo4NjQwMDAwMH0=', 'koa.sess.sig' => 'liV7oStLo', 'csrf-token' => 'Gmch9', @@ -75,12 +75,12 @@ public function testWrongCookie(): void $request = $this->parseStream($body); - $this->assertSame('GET', $request->getMethod()); - $this->assertSame('/foo/bar', $request->getUri()->getPath()); - $this->assertSame('1.1', $request->getProtocolVersion()); - $this->assertSame(['127.0.0.1:9912'], $request->getHeader('host')); - $this->assertSame(['ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3'], $request->getHeader('accept-language')); - $this->assertSame([ + self::assertSame('GET', $request->getMethod()); + self::assertSame('/foo/bar', $request->getUri()->getPath()); + self::assertSame('1.1', $request->getProtocolVersion()); + self::assertSame(['127.0.0.1:9912'], $request->getHeader('host')); + self::assertSame(['ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3'], $request->getHeader('accept-language')); + self::assertSame([ 'csrf-token.sig' => 'X0fR', ], $request->getCookieParams()); } @@ -111,12 +111,12 @@ public function testPostUrlEncoded(): void $request = $this->parseStream($body); - $this->assertSame('POST', $request->getMethod()); - $this->assertSame('/foo/bar', $request->getUri()->getPath()); - $this->assertSame('1.1', $request->getProtocolVersion()); - $this->assertSame(['foo.bar.com'], $request->getHeader('host')); - $this->assertSame('foo=bar&baz=qux&quux=corge+grault', $request->getBody()->__toString()); - $this->assertSame(['foo' => 'bar', 'baz' => 'qux', 'quux' => 'corge grault'], $request->getParsedBody()); + self::assertSame('POST', $request->getMethod()); + self::assertSame('/foo/bar', $request->getUri()->getPath()); + self::assertSame('1.1', $request->getProtocolVersion()); + self::assertSame(['foo.bar.com'], $request->getHeader('host')); + self::assertSame('foo=bar&baz=qux&quux=corge+grault', $request->getBody()->__toString()); + self::assertSame(['foo' => 'bar', 'baz' => 'qux', 'quux' => 'corge grault'], $request->getParsedBody()); } public function testPostMultipartFormData(): void @@ -161,26 +161,26 @@ public function testPostMultipartFormData(): void $request = $this->parseStream($headers . $body); - $this->assertSame('POST', $request->getMethod()); - $this->assertSame('/send-message.html', $request->getUri()->getPath()); - $this->assertSame('1.1', $request->getProtocolVersion()); - $this->assertSame(['webmail.example.com'], $request->getHeader('host')); + self::assertSame('POST', $request->getMethod()); + self::assertSame('/send-message.html', $request->getUri()->getPath()); + self::assertSame('1.1', $request->getProtocolVersion()); + self::assertSame(['webmail.example.com'], $request->getHeader('host')); // POST data - $this->assertEquals([ + self::assertEquals([ 'Authors' => '@roxblnfk and @butschster', 'MessageTitle' => 'Hello guys! The Buggregator is a great tool!', 'MessageText' => 'Do you know that Buggregator could be called Deburger? But we decided to name it Buggregator.', ], $request->getParsedBody()); // Uploaded files - $this->assertCount(2, $files = $request->getUploadedFiles()); + self::assertCount(2, $files = $request->getUploadedFiles()); /** @var UploadedFileInterface[] $files */ - $this->assertSame('deburger.png', $files['AttachedFile1'][0]->getClientFilename()); - $this->assertSame('image/png', $files['AttachedFile1'][0]->getClientMediaType()); - $this->assertSame($file1, $files['AttachedFile1'][0]->getStream()->__toString()); + self::assertSame('deburger.png', $files['AttachedFile1'][0]->getClientFilename()); + self::assertSame('image/png', $files['AttachedFile1'][0]->getClientMediaType()); + self::assertSame($file1, $files['AttachedFile1'][0]->getStream()->__toString()); - $this->assertSame('buggregator.png', $files['AttachedFile2'][0]->getClientFilename()); - $this->assertSame('image/png', $files['AttachedFile2'][0]->getClientMediaType()); - $this->assertSame($file2, $files['AttachedFile2'][0]->getStream()->__toString()); + self::assertSame('buggregator.png', $files['AttachedFile2'][0]->getClientFilename()); + self::assertSame('image/png', $files['AttachedFile2'][0]->getClientMediaType()); + self::assertSame($file2, $files['AttachedFile2'][0]->getStream()->__toString()); } public function testGzippedBody(): void diff --git a/tests/Unit/Traffic/Parser/MultipartBodyParserTest.php b/tests/Unit/Traffic/Parser/MultipartBodyParserTest.php index b21e274a..001efcd8 100644 --- a/tests/Unit/Traffic/Parser/MultipartBodyParserTest.php +++ b/tests/Unit/Traffic/Parser/MultipartBodyParserTest.php @@ -43,9 +43,9 @@ public function testParse(): void $result = $this->parse($body, 'your-boundary'); - $this->assertCount(2, $result); - $this->assertInstanceOf(Field::class, $result[0]); - $this->assertInstanceOf(Field::class, $result[1]); + self::assertCount(2, $result); + self::assertInstanceOf(Field::class, $result[0]); + self::assertInstanceOf(Field::class, $result[1]); } public function testWithFileAttach(): void @@ -82,35 +82,35 @@ public function testWithFileAttach(): void $result = $this->parse($body, 'Asrf456BGe4h'); - $this->assertCount(5, $result); - $this->assertInstanceOf(Field::class, $result[0]); - $this->assertInstanceOf(Field::class, $result[1]); + self::assertCount(5, $result); + self::assertInstanceOf(Field::class, $result[0]); + self::assertInstanceOf(Field::class, $result[1]); // POST data - $this->assertSame('Authors', $result[0]->getName()); - $this->assertSame('@roxblnfk and @butschster', $result[0]->getValue()); - $this->assertSame('MessageTitle', $result[1]->getName()); - $this->assertSame('Hello guys! The Buggregator is a great tool!', $result[1]->getValue()); - $this->assertSame('MessageText', $result[2]->getName()); - $this->assertSame( + self::assertSame('Authors', $result[0]->getName()); + self::assertSame('@roxblnfk and @butschster', $result[0]->getValue()); + self::assertSame('MessageTitle', $result[1]->getName()); + self::assertSame('Hello guys! The Buggregator is a great tool!', $result[1]->getValue()); + self::assertSame('MessageText', $result[2]->getName()); + self::assertSame( 'Do you know that Buggregator could be called Deburger? But we decided to name it Buggregator.', $result[2]->getValue(), ); $file = $result[3]; // Uploaded files - $this->assertInstanceOf(File::class, $file); - $this->assertSame('AttachedFile1', $file->getName()); - $this->assertSame('deburger.png', $file->getClientFilename()); - $this->assertSame('image/png', $file->getClientMediaType()); - $this->assertSame($file1, $file->getStream()->__toString()); + self::assertInstanceOf(File::class, $file); + self::assertSame('AttachedFile1', $file->getName()); + self::assertSame('deburger.png', $file->getClientFilename()); + self::assertSame('image/png', $file->getClientMediaType()); + self::assertSame($file1, $file->getStream()->__toString()); $file = $result[4]; - $this->assertInstanceOf(File::class, $file); - $this->assertSame('AttachedFile2', $file->getName()); - $this->assertSame('buggregator.png', $file->getClientFilename()); - $this->assertSame('image/png', $file->getClientMediaType()); - $this->assertSame($file2, $file->getStream()->__toString()); + self::assertInstanceOf(File::class, $file); + self::assertSame('AttachedFile2', $file->getName()); + self::assertSame('buggregator.png', $file->getClientFilename()); + self::assertSame('image/png', $file->getClientMediaType()); + self::assertSame($file2, $file->getStream()->__toString()); } private function makeStream(string $body): StreamInterface diff --git a/tests/Unit/Traffic/Parser/SmtpParserTest.php b/tests/Unit/Traffic/Parser/SmtpParserTest.php index f07b9137..7dd2b8fb 100644 --- a/tests/Unit/Traffic/Parser/SmtpParserTest.php +++ b/tests/Unit/Traffic/Parser/SmtpParserTest.php @@ -27,17 +27,17 @@ public function testParseSimpleBody(): void SMTP, 10); $message = $this->parse($data); - $this->assertSame(\implode('', $data), (string) $message->getBody()); - $this->assertCount(1, $message->getMessages()); + self::assertSame(\implode('', $data), (string) $message->getBody()); + self::assertCount(1, $message->getMessages()); // Check headers - $this->assertEquals([ + self::assertEquals([ 'From' => ['Some User '], 'To' => ['User1 '], 'Subject' => ['Very important theme'], 'Content-Type' => ['text/plain'], ], $message->getHeaders()); // Check body - $this->assertSame('Hi!', $message->getMessages()[0]->getValue()); + self::assertSame('Hi!', $message->getMessages()[0]->getValue()); } public function testParseMultipart(): void @@ -88,22 +88,22 @@ public function testParseMultipart(): void // Check contacts // Sender - $this->assertCount(2, $message->getSender()); - $this->assertNull($message->getSender()[0]->name); - $this->assertSame('someusername@foo.bar', $message->getSender()[0]->email); - $this->assertNull($message->getSender()[1]->name); - $this->assertSame('sender@example.com', $message->getSender()[1]->email); + self::assertCount(2, $message->getSender()); + self::assertNull($message->getSender()[0]->name); + self::assertSame('someusername@foo.bar', $message->getSender()[0]->email); + self::assertNull($message->getSender()[1]->name); + self::assertSame('sender@example.com', $message->getSender()[1]->email); // BCC - $this->assertCount(2, $message->getBcc()); - $this->assertNull($message->getBcc()[0]->name); - $this->assertSame('user1@company.tld', $message->getBcc()[0]->email); - $this->assertNull($message->getBcc()[1]->name); - $this->assertSame('user2@company.tld', $message->getBcc()[1]->email); - - $this->assertSame(\implode('', $data), (string) $message->getBody()); - $this->assertCount(3, $message->getMessages()); + self::assertCount(2, $message->getBcc()); + self::assertNull($message->getBcc()[0]->name); + self::assertSame('user1@company.tld', $message->getBcc()[0]->email); + self::assertNull($message->getBcc()[1]->name); + self::assertSame('user2@company.tld', $message->getBcc()[1]->email); + + self::assertSame(\implode('', $data), (string) $message->getBody()); + self::assertCount(3, $message->getMessages()); // Check headers - $this->assertEquals([ + self::assertEquals([ 'From' => ['sender@example.com'], 'To' => ['recipient@example.com'], 'Subject' => ['Multipart Email Example'], @@ -113,40 +113,40 @@ public function testParseMultipart(): void // Check bodies // Body 0 - $this->assertSame( + self::assertSame( "Plain text email goes here!\r\nThis is the fallback if email client does not support HTML\r\n", $message->getMessages()[0]->getValue(), ); - $this->assertEquals([ + self::assertEquals([ 'Content-Type' => ['text/plain; charset="utf-8"'], 'Content-Transfer-Encoding' => ['quoted-printable'], 'Content-Disposition' => ['inline'], ], $message->getMessages()[0]->getHeaders()); // Body 1 - $this->assertSame( + self::assertSame( "

This is the HTML Section!

\r\n

This is what displays in most modern email clients

\r\n", $message->getMessages()[1]->getValue(), ); - $this->assertEquals([ + self::assertEquals([ 'Content-Type' => ['text/html; charset="utf-8"'], 'Content-Transfer-Encoding' => ['quoted-printable'], 'Content-Disposition' => ['inline'], ], $message->getMessages()[1]->getHeaders()); // Body 2 - $this->assertSame( + self::assertSame( "Apple Watch formatted content\r\n", $message->getMessages()[2]->getValue(), ); - $this->assertEquals([ + self::assertEquals([ 'Content-Type' => ['text/watch-html; charset="utf-8"'], 'Content-Transfer-Encoding' => ['quoted-printable'], 'Content-Disposition' => ['inline'], ], $message->getMessages()[2]->getHeaders()); // Check attachments - $this->assertCount(1, $message->getAttachments()); + self::assertCount(1, $message->getAttachments()); } private function parse(array|string $body, array $protocol = []): Message\Smtp diff --git a/tests/Unit/Traffic/Proto/Server/Version/V1Test.php b/tests/Unit/Traffic/Proto/Server/Version/V1Test.php index 15b002fc..b456efba 100644 --- a/tests/Unit/Traffic/Proto/Server/Version/V1Test.php +++ b/tests/Unit/Traffic/Proto/Server/Version/V1Test.php @@ -24,7 +24,7 @@ public function testIsSuppoerted(string $payload, bool $isSupported): void { $decoder = new V1(); - $this->assertSame($isSupported, $decoder->isSupport($payload)); + self::assertSame($isSupported, $decoder->isSupport($payload)); } public function testDecode(): void @@ -33,9 +33,9 @@ public function testDecode(): void $request = $decoder->decode('1|0.1|9a06581c-3bec-4cf1-8412-b2a40bb36a76|[{},{}]'); - $this->assertSame(1, $request->protocol); - $this->assertSame('0.1', $request->client); - $this->assertSame('9a06581c-3bec-4cf1-8412-b2a40bb36a76', $request->uuid); - $this->assertSame('[{},{}]', $request->payload); + self::assertSame(1, $request->protocol); + self::assertSame('0.1', $request->client); + self::assertSame('9a06581c-3bec-4cf1-8412-b2a40bb36a76', $request->uuid); + self::assertSame('[{},{}]', $request->payload); } }