diff --git a/tests/src/Unit/Adapter/Psr7/ResponseTest.php b/tests/src/Unit/Adapter/Psr7/ResponseTest.php index 9afc448f..da47b32b 100644 --- a/tests/src/Unit/Adapter/Psr7/ResponseTest.php +++ b/tests/src/Unit/Adapter/Psr7/ResponseTest.php @@ -27,30 +27,6 @@ protected function setUp(): void ); } - public function testGetStatusCode(): void - { - $this->assertEquals(200, $this->response->getStatusCode()); - } - - public function testWithStatus(): void - { - $withStatus = $this->response->withStatus(404, 'Not Found'); - $this->assertEquals(404, $withStatus->getStatusCode()); - $this->assertEquals('Not Found', $withStatus->getReasonPhrase()); - } - - public function testGetReasonPhrase(): void - { - $this->assertEquals('OK', $this->response->getReasonPhrase()); - } - - public function testGetHarResponse(): void - { - $harResponse = $this->response->getHarResponse(); - $this->assertInstanceOf(\Deviantintegral\Har\Response::class, $harResponse); - $this->assertEquals(200, $harResponse->getStatus()); - } - public function testWithHeader(): void { $withHeader = $this->response->withHeader('X-Test', 'value'); @@ -78,29 +54,6 @@ public function testGetHeaderLineWhenHeaderNotPresent(): void $this->assertEquals('', $this->response->getHeaderLine('X-NonExistent')); } - public function testGetHeader(): void - { - $headers = $this->response->getHeader('Content-Type'); - $this->assertEquals(['text/html; charset=UTF-8'], $headers); - } - - public function testHasHeader(): void - { - $this->assertTrue($this->response->hasHeader('Content-Type')); - $this->assertFalse($this->response->hasHeader('X-NonExistent')); - } - - public function testGetHeaders(): void - { - $headers = $this->response->getHeaders(); - $this->assertArrayHasKey('Content-Type', $headers); - } - - public function testGetProtocolVersion(): void - { - $this->assertEquals('1.1', $this->response->getProtocolVersion()); - } - public function testWithProtocolVersion(): void { $withProtocol = $this->response->withProtocolVersion('2.0'); @@ -113,44 +66,6 @@ public function testWithoutHeader(): void $this->assertFalse($withoutHeader->hasHeader('Content-Type')); } - public function testWithAddedHeader(): void - { - $withAdded = $this->response->withAddedHeader('X-Custom', 'value1'); - $this->assertEquals(['value1'], $withAdded->getHeader('X-Custom')); - - $withMultiple = $withAdded->withAddedHeader('X-Custom', 'value2'); - $this->assertEquals(['value1', 'value2'], $withMultiple->getHeader('X-Custom')); - } - - public function testWithAddedHeaderArrayValue(): void - { - $withAdded = $this->response->withAddedHeader('X-Custom', ['value1', 'value2']); - $this->assertEquals(['value1', 'value2'], $withAdded->getHeader('X-Custom')); - } - - public function testGetBody(): void - { - $body = $this->response->getBody(); - $this->assertInstanceOf(\Psr\Http\Message\StreamInterface::class, $body); - - // Verify the body content matches the response content - $bodyContent = $body->getContents(); - $this->assertNotEmpty($bodyContent); - } - - public function testWithBody(): void - { - $newBodyContent = 'Test body content'; - $newBody = \GuzzleHttp\Psr7\Utils::streamFor($newBodyContent); - - $withBody = $this->response->withBody($newBody); - $this->assertInstanceOf(Response::class, $withBody); - - // Verify the new body content - $resultBody = $withBody->getBody(); - $this->assertEquals($newBodyContent, $resultBody->getContents()); - } - public function testWithStatusDoesNotModifyOriginal(): void { $original = $this->response; diff --git a/tests/src/Unit/Adapter/Psr7/ServerRequestTest.php b/tests/src/Unit/Adapter/Psr7/ServerRequestTest.php index b40dd254..0878f96e 100644 --- a/tests/src/Unit/Adapter/Psr7/ServerRequestTest.php +++ b/tests/src/Unit/Adapter/Psr7/ServerRequestTest.php @@ -168,7 +168,6 @@ public function testGetAttributes(): void public function testGetAttribute(): void { // Attributes are not part of HAR spec, always returns default - $this->assertNull($this->serverRequest->getAttribute('custom_attr')); $this->assertNull($this->serverRequest->getAttribute('nonexistent')); $this->assertEquals('default', $this->serverRequest->getAttribute('nonexistent', 'default')); } diff --git a/tests/src/Unit/BrowserTest.php b/tests/src/Unit/BrowserTest.php deleted file mode 100644 index 7dac2790..00000000 --- a/tests/src/Unit/BrowserTest.php +++ /dev/null @@ -1,73 +0,0 @@ -getSerializer(); - $browser = (new Browser()) - ->setName('BrowserTest') - ->setVersion('1.0') - ->setComment('Test case'); - $serialized = $serializer->serialize($browser, 'json'); - $this->assertEquals( - [ - 'name' => 'BrowserTest', - 'version' => '1.0', - 'comment' => 'Test case', - ], - json_decode($serialized, true) - ); - - $deserialized = $serializer->deserialize( - $serialized, - Browser::class, - 'json' - ); - $this->assertEquals($browser, $deserialized); - } - - public function testGet(): void - { - $browser = (new Browser()) - ->setName('BrowserTest') - ->setVersion('1.0') - ->setComment('Test case'); - - $this->assertEquals('BrowserTest', $browser->getName()); - $this->assertEquals('1.0', $browser->getVersion()); - $this->assertEquals('Test case', $browser->getComment()); - } - - public function testClone(): void - { - $browser = (new Browser()) - ->setName('BrowserTest') - ->setVersion('1.0') - ->setComment('Test case'); - - $clonedBrowser = clone $browser; - - // Verify the clone is a different object - $this->assertNotSame($browser, $clonedBrowser); - - // Verify the clone has the same property values - $this->assertEquals($browser->getName(), $clonedBrowser->getName()); - $this->assertEquals($browser->getVersion(), $clonedBrowser->getVersion()); - $this->assertEquals($browser->getComment(), $clonedBrowser->getComment()); - - // Verify modifying the clone doesn't affect the original - $clonedBrowser->setName('ModifiedBrowser'); - $this->assertEquals('BrowserTest', $browser->getName()); - $this->assertEquals('ModifiedBrowser', $clonedBrowser->getName()); - } -} diff --git a/tests/src/Unit/CookieTest.php b/tests/src/Unit/CookieTest.php index 0818a2d9..9dbc61ad 100644 --- a/tests/src/Unit/CookieTest.php +++ b/tests/src/Unit/CookieTest.php @@ -26,11 +26,6 @@ public function testSerialize(): void ->setSecure(true) ->setValue('Test value'); - $this->assertTrue($cookie->hasSecure()); - $this->assertNotNull($cookie->isSecure()); - $this->assertTrue($cookie->hasHttpOnly()); - $this->assertNotNull($cookie->isHttpOnly()); - $serialized = $serializer->serialize($cookie, 'json'); $this->assertEquals( [ @@ -62,9 +57,7 @@ public function testSerializeWithoutOptionalAttributes(): void ->setValue('Test value'); $this->assertFalse($cookie->hasSecure()); - $this->assertNull($cookie->isSecure()); $this->assertFalse($cookie->hasHttpOnly()); - $this->assertNull($cookie->isHttpOnly()); $serialized = $serializer->serialize($cookie, 'json'); $this->assertEquals( diff --git a/tests/src/Unit/EntryTest.php b/tests/src/Unit/EntryTest.php index 6209de55..a557392f 100644 --- a/tests/src/Unit/EntryTest.php +++ b/tests/src/Unit/EntryTest.php @@ -35,24 +35,6 @@ public function testHasInitiator(): void $this->assertTrue($first->hasInitiator()); } - public function testSerializationOfEntryWithAddedInitiatorOfTypeOther(): void - { - // Load a HAR file into an object. - $id = 'www.softwareishard.com-empty-login.har'; - $har = $this->repository->load($id); - $first = $har->getLog()->getEntries()[0]; - $first->setInitiator((new Initiator())->setType('other')); - - $serialized = $this->getSerializer()->serialize($har, 'json'); - $actual = json_decode($serialized, true); - $this->assertIsArray($actual['log']['entries'][0]['_initiator']); - $this->assertEquals('other', $actual['log']['entries'][0]['_initiator']['type']); - $this->assertArrayNotHasKey('url', $actual['log']['entries'][0]['_initiator']); - $this->assertArrayNotHasKey('lineNumber', $actual['log']['entries'][0]['_initiator']); - - $this->assertArrayNotHasKey('_initiator', $actual['log']['entries'][1]); - } - public function testGetSetPageref(): void { $entry = (new Entry())->setPageref('page_1'); diff --git a/tests/src/Unit/HeaderTest.php b/tests/src/Unit/HeaderTest.php deleted file mode 100644 index 4de81706..00000000 --- a/tests/src/Unit/HeaderTest.php +++ /dev/null @@ -1,34 +0,0 @@ -setName('Host') - ->setValue('www.example.com') - ->setComment('Test value'); - - $serializer = $this->getSerializer(); - $serialized = $serializer->serialize($header, 'json'); - $this->assertEquals([ - 'name' => 'Host', - 'value' => 'www.example.com', - 'comment' => 'Test value', - ], json_decode($serialized, true)); - - $deserialized = $serializer->deserialize($serialized, Header::class, 'json'); - $this->assertEquals($header, $deserialized); - } -} diff --git a/tests/src/Unit/InitiatorTest.php b/tests/src/Unit/InitiatorTest.php index e20378d0..27b344b0 100644 --- a/tests/src/Unit/InitiatorTest.php +++ b/tests/src/Unit/InitiatorTest.php @@ -26,9 +26,7 @@ public function testInitiatorWithTypeOther(): void $this->assertDeserialize($serialized, Initiator::class, $initiator); - $this->assertFalse($initiator->hasUrl()); $this->assertNull($initiator->getUrl()); - $this->assertFalse($initiator->hasLineNumber()); $this->assertNull($initiator->getLineNumber()); } @@ -55,8 +53,6 @@ public function testInitiatorWithTypeParser(): void $initiator->setUrl(new Uri('https://www.php.net/')); $this->assertDeserialize($serialized, Initiator::class, $initiator); $this->assertTrue($initiator->hasLineNumber()); - $this->assertIsNumeric($initiator->getLineNumber()); $this->assertTrue($initiator->hasUrl()); - $this->assertNotNull($initiator->getUrl()); } } diff --git a/tests/src/Unit/MissingLogKeyTest.php b/tests/src/Unit/MissingLogKeyTest.php index 4bdc8500..0a68a8cc 100644 --- a/tests/src/Unit/MissingLogKeyTest.php +++ b/tests/src/Unit/MissingLogKeyTest.php @@ -4,7 +4,6 @@ namespace Deviantintegral\Har\Tests\Unit; -use Deviantintegral\Har\Repository\HarFileRepository; use Deviantintegral\Har\Serializer; use JMS\Serializer\Exception\RuntimeException; @@ -13,38 +12,6 @@ */ class MissingLogKeyTest extends HarTestBase { - /** - * Tests that deserializeHar() throws RuntimeException when 'log' key is missing. - * - * Before this fix, the HAR would deserialize successfully but accessing - * the log property would throw an Error about uninitialized property. - * Now, deserializeHar() validates and throws a proper exception immediately. - */ - public function testMissingLogKeyThrowsException(): void - { - $repository = new HarFileRepository(__DIR__.'/../../fixtures/edge-cases'); - $serializer = new Serializer(); - - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('HAR file must contain a "log" key'); - - $json = $repository->loadJson('missing-log.har'); - $serializer->deserializeHar($json); - } - - /** - * Tests that deserializeHar() throws RuntimeException for invalid JSON structure. - */ - public function testEmptyJsonThrowsException(): void - { - $serializer = new Serializer(); - - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('HAR file must contain a "log" key'); - - $serializer->deserializeHar('{}'); - } - /** * Tests that deserializeHar() throws RuntimeException when JSON is not an object. */ diff --git a/tests/src/Unit/PageTest.php b/tests/src/Unit/PageTest.php index a841202e..ab362ad7 100644 --- a/tests/src/Unit/PageTest.php +++ b/tests/src/Unit/PageTest.php @@ -38,21 +38,6 @@ public function testSerialize(): void ], json_decode($serialized, true) ); - - $deserialized = $serializer->deserialize($serialized, Page::class, 'json'); - $this->assertEquals($page, $deserialized); - } - - public function testGetSetId(): void - { - $page = (new Page())->setId('page_123'); - $this->assertEquals('page_123', $page->getId()); - } - - public function testGetSetTitle(): void - { - $page = (new Page())->setTitle('Test Page Title'); - $this->assertEquals('Test Page Title', $page->getTitle()); } public function testGetSetPageTimings(): void diff --git a/tests/src/Unit/PageTimingTest.php b/tests/src/Unit/PageTimingTest.php index 2e1a24e1..c48955ae 100644 --- a/tests/src/Unit/PageTimingTest.php +++ b/tests/src/Unit/PageTimingTest.php @@ -29,12 +29,5 @@ public function testSerialize(): void ], json_decode($serialized, true) ); - - $deserialized = $serializer->deserialize( - $serialized, - PageTimings::class, - 'json' - ); - $this->assertEquals($creator, $deserialized); } } diff --git a/tests/src/Unit/QueryStringTest.php b/tests/src/Unit/QueryStringTest.php deleted file mode 100644 index c1ce9eff..00000000 --- a/tests/src/Unit/QueryStringTest.php +++ /dev/null @@ -1,31 +0,0 @@ -setName('Host') - ->setValue('www.example.com') - ->setComment('Test value'); - - $serializer = $this->getSerializer(); - $this->assertEquals( - [ - 'name' => 'Host', - 'value' => 'www.example.com', - 'comment' => 'Test value', - ], - json_decode($serializer->serialize($query, 'json'), true) - ); - } -} diff --git a/tests/src/Unit/ResponseTest.php b/tests/src/Unit/ResponseTest.php index 68acc096..13af1320 100644 --- a/tests/src/Unit/ResponseTest.php +++ b/tests/src/Unit/ResponseTest.php @@ -27,32 +27,6 @@ public function testFromPsr7(): void $this->assertEquals('Who needs reasons?', $response->getStatusText()); } - public function testGetSetStatus(): void - { - $response = (new \Deviantintegral\Har\Response())->setStatus(404); - $this->assertEquals(404, $response->getStatus()); - } - - public function testGetSetStatusText(): void - { - $response = (new \Deviantintegral\Har\Response())->setStatusText('Not Found'); - $this->assertEquals('Not Found', $response->getStatusText()); - } - - public function testGetSetContent(): void - { - $content = (new Content())->setText('test content'); - $response = (new \Deviantintegral\Har\Response())->setContent($content); - $this->assertSame($content, $response->getContent()); - } - - public function testGetSetRedirectURL(): void - { - $uri = new Uri('https://www.example.com/redirect'); - $response = (new \Deviantintegral\Har\Response())->setRedirectURL($uri); - $this->assertSame($uri, $response->getRedirectURL()); - } - public function testSerialize(): void { $serializer = $this->getSerializer(); @@ -87,18 +61,6 @@ public function testSerialize(): void $this->assertEquals($response->getComment(), $deserialized->getComment()); } - public function testSetHeadersCalculatesCorrectSize(): void - { - $response = new \Deviantintegral\Har\Response(); - - // Test with single header: "Content-Type: application/json" - // Size calculation: strlen("Content-Type") + 2 + strlen("application/json") + 2 = 12 + 2 + 16 + 2 = 32 - // Plus final 2 for double CRLF: 32 + 2 = 34 - $headers = [(new Header())->setName('Content-Type')->setValue('application/json')]; - $response->setHeaders($headers); - $this->assertSame(34, $response->getHeadersSize()); - } - public function testSetHeadersWithMultipleHeaders(): void { $response = new \Deviantintegral\Har\Response(); @@ -124,15 +86,4 @@ public function testSetHeadersWithEmptyArray(): void $response->setHeaders([]); $this->assertSame(2, $response->getHeadersSize()); } - - public function testSetHeadersWithSingleCharacterValues(): void - { - $response = new \Deviantintegral\Har\Response(); - - // Test with minimal header to ensure each +2 is necessary - // "X: Y" = 1 + 2 + 1 + 2 = 6, plus final 2 = 8 - $headers = [(new Header())->setName('X')->setValue('Y')]; - $response->setHeaders($headers); - $this->assertSame(8, $response->getHeadersSize()); - } } diff --git a/tests/src/Unit/SharedFields/TextTraitTest.php b/tests/src/Unit/SharedFields/TextTraitTest.php index fe5d932d..9cf17b5a 100644 --- a/tests/src/Unit/SharedFields/TextTraitTest.php +++ b/tests/src/Unit/SharedFields/TextTraitTest.php @@ -12,63 +12,10 @@ */ class TextTraitTest extends TestCase { - public function testSetTextIsPublic(): void - { - // This test kills the PublicVisibility mutation in TextTrait::setText - // by using a class that uses the trait WITHOUT aliasing/overriding. - // - // Unlike PostData and Content which alias setText as traitSetText - // and provide their own public setText, TextTraitTestClass uses - // the trait's method directly. If the trait's method becomes - // protected, this test will fail with a fatal error. - $instance = new TextTraitTestClass(); - - // Calling setText from outside the class - would fail if protected - $result = $instance->setText('test content'); - - // Verify method chaining works (returns self) - $this->assertSame($instance, $result); - - // Verify the text was set - $this->assertTrue($instance->hasText()); - $this->assertEquals('test content', $instance->getText()); - } - - public function testSetTextWithNull(): void - { - $instance = new TextTraitTestClass(); - $instance->setText('initial'); - $this->assertTrue($instance->hasText()); - - // Setting null should clear the text - $instance->setText(null); - $this->assertFalse($instance->hasText()); - $this->assertNull($instance->getText()); - } - - public function testHasText(): void - { - $instance = new TextTraitTestClass(); - - // Initially no text - $this->assertFalse($instance->hasText()); - - // After setting text - $instance->setText('content'); - $this->assertTrue($instance->hasText()); - - // After clearing text - $instance->setText(null); - $this->assertFalse($instance->hasText()); - } - public function testGetText(): void { $instance = new TextTraitTestClass(); - // Initially null - $this->assertNull($instance->getText()); - // After setting $instance->setText('some text'); $this->assertEquals('some text', $instance->getText());