Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phpstan fixes #74

Open
wants to merge 5 commits into
base: 4.x-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ $urlEncodedContent = new UrlEncodedFormData(
]
);

$postRequest = PostRequest::newWithRequestContent( '/path/to/target/script.php', $urlEncodedContent );
$postRequest = new PostRequest( '/path/to/target/script.php', $urlEncodedContent );

$response = $client->sendRequest( $connection, $postRequest );
```
Expand Down Expand Up @@ -713,7 +713,7 @@ $multipartContent = new MultipartFormData(
]
);

$postRequest = PostRequest::newWithRequestContent( '/path/to/target/script.php', $multipartContent );
$postRequest = new PostRequest( '/path/to/target/script.php', $multipartContent );

$response = $client->sendRequest( $connection, $postRequest );
```
Expand Down Expand Up @@ -812,7 +812,7 @@ $jsonContent = new JsonData(
]
);

$postRequest = PostRequest::newWithRequestContent( '/path/to/target/script.php', $jsonContent );
$postRequest = new PostRequest( '/path/to/target/script.php', $jsonContent );

$response = $client->sendRequest( $connection, $postRequest );
```
Expand Down
5 changes: 3 additions & 2 deletions src/Requests/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ abstract class AbstractRequest implements ProvidesRequestData
public function __construct( string $scriptFilename, ?ComposesRequestContent $content = null )
{
$this->scriptFilename = $scriptFilename;
$this->content = $content;

if (null !== $content) {
$this->setContent( $content );
$this->contentLength = strlen( $content->getContent() );
$this->setContentType( $content->getContentType() );
}
}
Expand Down Expand Up @@ -148,7 +149,7 @@ public function getContent() : ?ComposesRequestContent

public function setContent( ComposesRequestContent $content ) : void
{
$this->content = $content;
$this->content = $content;
$this->contentLength = strlen( $content->getContent() );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/FileUpload/FileUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testCanUploadFiles( array $files ) : void
];

$multipartFormData = new MultipartFormData( $formData, $files );
$postRequest = PostRequest::newWithRequestContent(
$postRequest = new PostRequest(
dirname( __DIR__ ) . '/Workers/fileUploadWorker.php',
$multipartFormData
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/NetworkSocket/NetworkSocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@ static function ( $buffer ) use ( $unitTest, $data, &$passCounter )
*/
public function testCanGetLengthOfSentContent( int $length ) : void
{
$content = str_repeat( 'a', $length );
$content = new UrlEncodedFormData(['test' => str_repeat( 'a', $length )]);
$request = new PostRequest( $this->getWorkerPath( 'lengthWorker.php' ), $content );
$request->setContentType( '*/*' );
$result = $this->client->sendRequest( $this->connection, $request );

self::assertEquals( $length, $result->getBody() );
self::assertEquals( $length + 5, $result->getBody() );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ static function ( $buffer ) use ( $unitTest, $data, &$passCounter )
*/
public function testCanGetLengthOfSentContent( int $length ) : void
{
$content = str_repeat( 'a', $length );
$content = new UrlEncodedFormData(['test' => str_repeat( 'a', $length )]);
$request = new PostRequest( $this->getWorkerPath( 'lengthWorker.php' ), $content );

$response = $this->client->sendRequest( $this->connection, $request );
Expand Down
19 changes: 9 additions & 10 deletions tests/Unit/Requests/AbstractRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace hollodotme\FastCGI\Tests\Unit\Requests;

use hollodotme\FastCGI\Interfaces\ComposesRequestContent;
use hollodotme\FastCGI\RequestContents\UrlEncodedFormData;
use hollodotme\FastCGI\Requests\AbstractRequest;
use PHPUnit\Framework\ExpectationFailedException;
Expand Down Expand Up @@ -41,19 +42,17 @@ public function testCanGetDefaultValues( string $requestMethod ) : void
/**
* @param string $requestMethod
* @param string $scriptFilename
* @param string $content
*
* @return AbstractRequest
*/
private function getRequest( string $requestMethod, string $scriptFilename ) : AbstractRequest
private function getRequest( string $requestMethod, string $scriptFilename, ?ComposesRequestContent $content = null ) : AbstractRequest
{
return new class($requestMethod, $scriptFilename) extends AbstractRequest {
/** @var string */
private $requestMethod;
return new class($requestMethod, $scriptFilename, $content) extends AbstractRequest {
private string $requestMethod;

public function __construct( string $requestMethod, string $scriptFilename )
public function __construct( string $requestMethod, string $scriptFilename, ?ComposesRequestContent $content = null )
{
parent::__construct( $scriptFilename );
parent::__construct( $scriptFilename, $content );
$this->requestMethod = $requestMethod;
}

Expand Down Expand Up @@ -97,7 +96,7 @@ public function requestMethodProvider() : array
*/
public function testCanGetParametersArray( string $requestMethod ) : void
{
$request = $this->getRequest( $requestMethod, '/path/to/script.php', 'Unit-Test' );
$request = $this->getRequest( $requestMethod, '/path/to/script.php', new UrlEncodedFormData(['test' => 'unit']) );
$request->setCustomVar( 'UNIT', 'Test' );
$request->setRequestUri( '/unit/test/' );

Expand Down Expand Up @@ -142,7 +141,7 @@ public function testContentLengthChangesWithContent() : void
*/
public function testCanOverwriteVars() : void
{
$request = $this->getRequest( 'POST', '/path/to/script.php', 'Unit-Test' );
$request = $this->getRequest( 'POST', '/path/to/script.php', new UrlEncodedFormData(['test' => 'unit']) );
$request->setRemoteAddress( '10.100.10.1' );
$request->setRemotePort( 8599 );
$request->setServerSoftware( 'unit/test' );
Expand Down Expand Up @@ -185,7 +184,7 @@ public function testCanOverwriteVars() : void
*/
public function testCanResetCustomVars() : void
{
$request = $this->getRequest( 'POST', '/path/to/script.php', 'Unit-Test' );
$request = $this->getRequest( 'POST', '/path/to/script.php', new UrlEncodedFormData(['test' => 'unit']) );
$request->setCustomVar( 'UNIT', 'Test' );

self::assertSame( ['UNIT' => 'Test'], $request->getCustomVars() );
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Requests/DeleteRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class DeleteRequestTest extends TestCase
*/
public function testRequestMethodIsGet() : void
{
$request = new DeleteRequest( '/path/to/script.php', 'Unit-Test' );
$request = new DeleteRequest( '/path/to/script.php' );

self::assertSame( 'DELETE', $request->getRequestMethod() );
}
Expand All @@ -34,7 +34,7 @@ public function testCanCreateInstanceWithRequestContent() : void
]
);

$request = DeleteRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent );
$request = new DeleteRequest( '/path/to/script.php', $urlEncodedContent );

self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() );
self::assertSame( 'unit=test&test=unit', $request->getContent() );
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Requests/GetRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class GetRequestTest extends TestCase
*/
public function testRequestMethodIsGet() : void
{
$request = new GetRequest( '/path/to/script.php', 'Unit-Test' );
$request = new GetRequest( '/path/to/script.php' );

self::assertSame( 'GET', $request->getRequestMethod() );
}
Expand All @@ -34,7 +34,7 @@ public function testCanCreateInstanceWithRequestContent() : void
]
);

$request = GetRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent );
$request = new GetRequest( '/path/to/script.php', $urlEncodedContent );

self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() );
self::assertSame( 'unit=test&test=unit', $request->getContent() );
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Requests/PatchRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class PatchRequestTest extends TestCase
*/
public function testRequestMethodIsGet() : void
{
$request = new PatchRequest( '/path/to/script.php', 'Unit-Test' );
$request = new PatchRequest( '/path/to/script.php' );

self::assertSame( 'PATCH', $request->getRequestMethod() );
}
Expand All @@ -34,7 +34,7 @@ public function testCanCreateInstanceWithRequestContent() : void
]
);

$request = PatchRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent );
$request = new PatchRequest( '/path/to/script.php', $urlEncodedContent );

self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() );
self::assertSame( 'unit=test&test=unit', $request->getContent() );
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Requests/PostRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class PostRequestTest extends TestCase
*/
public function testRequestMethodIsPost() : void
{
$request = new PostRequest( '/path/to/script.php', 'Unit-Test' );
$request = new PostRequest( '/path/to/script.php' );

self::assertSame( 'POST', $request->getRequestMethod() );
}
Expand All @@ -34,7 +34,7 @@ public function testCanCreateInstanceWithRequestContent() : void
]
);

$request = PostRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent );
$request = new PostRequest( '/path/to/script.php', $urlEncodedContent );

self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() );
self::assertSame( 'unit=test&test=unit', $request->getContent() );
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Requests/PutRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class PutRequestTest extends TestCase
*/
public function testRequestMethodIsPut() : void
{
$request = new PutRequest( '/path/to/script.php', 'Unit-Test' );
$request = new PutRequest( '/path/to/script.php' );

self::assertSame( 'PUT', $request->getRequestMethod() );
}
Expand All @@ -34,7 +34,7 @@ public function testCanCreateInstanceWithRequestContent() : void
]
);

$request = PutRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent );
$request = new PutRequest( '/path/to/script.php', $urlEncodedContent );

self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() );
self::assertSame( 'unit=test&test=unit', $request->getContent() );
Expand Down
8 changes: 3 additions & 5 deletions tests/Unit/Sockets/SocketCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ public function testSocketWithResponseIsIdle() : void
);

$request = new PostRequest(
dirname( __DIR__, 2 ) . '/Integration/Workers/sleepWorker.php',
''
);
dirname( __DIR__, 2 ) . '/Integration/Workers/sleepWorker.php' );
$socket->sendRequest( $request );

/** @noinspection UnusedFunctionResultInspection */
Expand Down Expand Up @@ -281,7 +279,7 @@ public function testBusySocketIsNotIdle() : void
);

$socket->sendRequest(
new PostRequest( '/some/script.php', '' )
new PostRequest( '/some/script.php' )
);

self::assertNull( $this->collection->getIdleSocket( $connection ) );
Expand Down Expand Up @@ -487,7 +485,7 @@ public function testHasBusySockets() : void
);

$socket->sendRequest(
new PostRequest( '/some/sctipt.php', '' )
new PostRequest( '/some/sctipt.php' )
);

self::assertTrue( $this->collection->hasBusySockets() );
Expand Down
11 changes: 6 additions & 5 deletions tests/Unit/Sockets/SocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use hollodotme\FastCGI\Exceptions\TimedoutException;
use hollodotme\FastCGI\Exceptions\WriteFailedException;
use hollodotme\FastCGI\Interfaces\ProvidesResponseData;
use hollodotme\FastCGI\RequestContents\UrlEncodedFormData;
use hollodotme\FastCGI\Requests\PostRequest;
use hollodotme\FastCGI\SocketConnections\Defaults;
use hollodotme\FastCGI\SocketConnections\NetworkSocket;
Expand Down Expand Up @@ -79,7 +80,7 @@ public function testCanSendRequestAndFetchResponse() : void
$data = ['test-key' => 'unit'];
$request = new PostRequest(
dirname( __DIR__, 2 ) . '/Integration/Workers/worker.php',
http_build_query( $data )
new UrlEncodedFormData( $data )
);

$socket->sendRequest( $request );
Expand Down Expand Up @@ -108,7 +109,7 @@ public function testCanCollectResource() : void
$data = ['test-key' => 'unit'];
$request = new PostRequest(
dirname( __DIR__, 2 ) . '/Integration/Workers/worker.php',
http_build_query( $data )
new UrlEncodedFormData( $data )
);

$socket->collectResource( $resources );
Expand All @@ -135,7 +136,7 @@ public function testCanNotifyResponseCallback() : void
$data = ['test-key' => 'unit'];
$request = new PostRequest(
dirname( __DIR__, 2 ) . '/Integration/Workers/worker.php',
http_build_query( $data )
new UrlEncodedFormData( $data )
);
$request->addResponseCallbacks(
static function ( ProvidesResponseData $response )
Expand Down Expand Up @@ -163,7 +164,7 @@ public function testCanNotifyFailureCallback() : void
$data = ['test-key' => 'unit'];
$request = new PostRequest(
dirname( __DIR__, 2 ) . '/Integration/Workers/worker.php',
http_build_query( $data )
new UrlEncodedFormData( $data )
);
$request->addFailureCallbacks(
static function ( Throwable $throwable )
Expand Down Expand Up @@ -284,7 +285,7 @@ public function testIsUsableWhenInInitialState() : void
public function testIsNotUsableWhenTimedOut() : void
{
$socket = $this->getSocket();
$content = http_build_query( ['sleep' => 1, 'test-key' => 'unit'] );
$content = new UrlEncodedFormData( ['sleep' => 1, 'test-key' => 'unit'] );
$request = new PostRequest( dirname( __DIR__, 2 ) . '/Integration/Workers/sleepWorker.php', $content );
$socket->sendRequest( $request );

Expand Down