diff --git a/phpstan.neon b/phpstan.neon index af2c49d..49cb743 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,5 @@ parameters: level: 8 paths: - - src \ No newline at end of file + - src + - tests \ No newline at end of file diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 5d4cb91..3c17e1e 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -2,6 +2,7 @@ namespace Sysix\LexOffice\Tests; +use Sysix\LexOffice\Api; use Sysix\LexOffice\Clients\Contact; use Sysix\LexOffice\Clients\Country; use Sysix\LexOffice\Clients\CreditNote; @@ -19,9 +20,14 @@ use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Clients\RecurringTemplate; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\MockObject\MockObject; class ApiTest extends TestClient { + /** + * @param Response $response + * @return Api&MockObject + */ public function createApiMockObject(Response $response) { $stub = parent::createApiMockObject($response); @@ -30,7 +36,7 @@ public function createApiMockObject(Response $response) return $stub; } - public function testClients() + public function testClients(): void { $stub = $this->createApiMockObject(new Response()); @@ -52,7 +58,7 @@ public function testClients() $this->assertInstanceOf(PostingCategory::class, $stub->postingCategory()); } - public function testApiUrl() + public function testApiUrl(): void { $stub = $this->createApiMockObject( new Response(200, [], 'post-content') @@ -66,7 +72,7 @@ public function testApiUrl() $this->assertStringStartsWith('test.de', $stub->request->getUri()->getHost()); } - public function testGetResponse() + public function testGetResponse(): void { $responseMock = new Response(200, [], 'response-body'); $stub = $this->createApiMockObject($responseMock); @@ -80,7 +86,7 @@ public function testGetResponse() $this->assertEquals($responseMock->getReasonPhrase(), $response->getReasonPhrase()); } - public function testRequestHeaders() + public function testRequestHeaders(): void { $stub = $this->createApiMockObject( new Response(200, [], 'post-content') diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index b7efe57..eb4fd6c 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -8,7 +8,7 @@ class ContactTest extends TestClient { - public function testGenerateUrl() + public function testGenerateUrl(): void { $stub = $this->createClientMockObject( Contact::class, @@ -21,7 +21,7 @@ public function testGenerateUrl() ); } - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Contact::class, @@ -35,7 +35,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Contact::class, @@ -47,7 +47,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testUpdate() + public function testUpdate(): void { $stub = $this->createClientMockObject( Contact::class, diff --git a/tests/Clients/CountryTest.php b/tests/Clients/CountryTest.php index 33bd2d8..46389bb 100644 --- a/tests/Clients/CountryTest.php +++ b/tests/Clients/CountryTest.php @@ -8,7 +8,7 @@ class CountryTest extends TestClient { - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Country::class, diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 56ed25e..562e8da 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -8,7 +8,7 @@ class CreditNoteTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( CreditNote::class, @@ -22,7 +22,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( CreditNote::class, @@ -34,7 +34,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( CreditNote::class, diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index fb358fb..566a7af 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -8,7 +8,7 @@ class DownPaymentInvoiceTest extends TestClient { - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( DownPaymentInvoice::class, @@ -20,7 +20,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( DownPaymentInvoice::class, diff --git a/tests/Clients/EventTest.php b/tests/Clients/EventTest.php index 4a21bf5..eeee8d7 100644 --- a/tests/Clients/EventTest.php +++ b/tests/Clients/EventTest.php @@ -9,7 +9,7 @@ class EventTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Event::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Event::class, @@ -35,7 +35,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDelete() + public function testDelete(): void { $stub = $this->createClientMockObject( Event::class, diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index c1f2bfa..9ad18a7 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -10,7 +10,7 @@ class FileTest extends TestClient { - public function testUploadNotSupportedExtension() + public function testUploadNotSupportedExtension(): void { $this->expectException(LexOfficeApiException::class); @@ -22,7 +22,7 @@ public function testUploadNotSupportedExtension() $stub->upload('not_allowed.gif', 'voucher'); } - public function testUploadNotFound() + public function testUploadNotFound(): void { $this->expectException(LexOfficeApiException::class); @@ -34,7 +34,7 @@ public function testUploadNotFound() $stub->upload('not_existing.jpg', 'voucher'); } - public function testUploadToBig() + public function testUploadToBig(): void { $this->expectException(LexOfficeApiException::class); @@ -45,7 +45,12 @@ public function testUploadToBig() $this->createCacheDir(); $file = $this->getCacheDir() . '/somefile.jpg'; - $fp = fopen($file, 'w+'); // + $fp = fopen($file, 'w+'); + + if ($fp === false) { + $this->fail('could not open file ' . $file); + } + fseek($fp, File::MAX_FILE_SIZE + 1,SEEK_CUR); fwrite($fp,'a'); fclose($fp); @@ -55,7 +60,7 @@ public function testUploadToBig() unlink($file); } - public function testUpload() + public function testUpload(): void { $stub = $this->createClientMockObject( File::class, @@ -64,7 +69,12 @@ public function testUpload() $this->createCacheDir(); $file = $this->getCacheDir() . '/somefile2.jpg'; - $fp = fopen($file, 'w+'); // + $fp = fopen($file, 'w+'); + + if ($fp === false) { + $this->fail('could not open file ' . $file); + } + fseek($fp, 5,SEEK_CUR); fwrite($fp,'a'); fclose($fp); diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index bba0ab3..794f69c 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -9,7 +9,7 @@ class InvoiceTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Invoice::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Invoice::class, @@ -35,7 +35,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Invoice::class, @@ -47,7 +47,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( Invoice::class, diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index 6e44251..f5a9f44 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -9,7 +9,7 @@ class OrderConfirmationTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( OrderConfirmation::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( OrderConfirmation::class, @@ -35,7 +35,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( OrderConfirmation::class, @@ -47,7 +47,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( OrderConfirmation::class, diff --git a/tests/Clients/PaymentConditionTest.php b/tests/Clients/PaymentConditionTest.php index 276bc82..0a3959c 100644 --- a/tests/Clients/PaymentConditionTest.php +++ b/tests/Clients/PaymentConditionTest.php @@ -8,7 +8,7 @@ class PaymentConditionTest extends TestClient { - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( PaymentCondition::class, diff --git a/tests/Clients/PaymentTest.php b/tests/Clients/PaymentTest.php index a5ecb62..a2b179c 100644 --- a/tests/Clients/PaymentTest.php +++ b/tests/Clients/PaymentTest.php @@ -8,7 +8,7 @@ class PaymentTest extends TestClient { - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Payment::class, diff --git a/tests/Clients/ProfileTest.php b/tests/Clients/ProfileTest.php index 4dcb70d..1ddc371 100644 --- a/tests/Clients/ProfileTest.php +++ b/tests/Clients/ProfileTest.php @@ -8,7 +8,7 @@ class ProfileTest extends TestClient { - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Profile::class, diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index eea48ec..23d4a9d 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -9,7 +9,7 @@ class QuotationTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Quotation::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Quotation::class, @@ -35,7 +35,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Quotation::class, @@ -47,7 +47,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( Quotation::class, diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index b5d8e4a..7ba083b 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -9,7 +9,7 @@ class VoucherListTest extends TestClient { - public function testGenerateUrl() + public function testGenerateUrl(): void { $stub = $this->createClientMockObject( VoucherList::class, diff --git a/tests/Clients/VoucherTest.php b/tests/Clients/VoucherTest.php index b250bf0..5ed5a6c 100644 --- a/tests/Clients/VoucherTest.php +++ b/tests/Clients/VoucherTest.php @@ -9,7 +9,7 @@ class VoucherTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Voucher::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Voucher::class, @@ -35,7 +35,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Voucher::class, @@ -47,7 +47,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testUpdate() + public function testUpdate(): void { $stub = $this->createClientMockObject( Voucher::class, diff --git a/tests/PaginationClientTest.php b/tests/PaginationClientTest.php index 494434a..96c652e 100644 --- a/tests/PaginationClientTest.php +++ b/tests/PaginationClientTest.php @@ -7,7 +7,7 @@ class PaginationClientTest extends TestClient { - public function testGenerateUrl() + public function testGenerateUrl(): void { $stub = $this->createPaginationClientMockObject( [new Response()] @@ -19,7 +19,7 @@ public function testGenerateUrl() ); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createPaginationClientMockObject( [new Response(200, [], '{"content": [], "totalPages": 1}')] @@ -44,7 +44,7 @@ public function testGetAll() ); } - public function testGetPage() + public function testGetPage(): void { $stub = $this->createPaginationClientMockObject( [new Response(200, [], '{"content": [], "totalPages": 1}')] diff --git a/tests/TestClient.php b/tests/TestClient.php index 17902bf..66e08a2 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -4,6 +4,7 @@ use Sysix\LexOffice\Api; use Sysix\LexOffice\PaginationClient; +use Sysix\LexOffice\ClientInterface; use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; @@ -17,7 +18,7 @@ class TestClient extends TestCase { /** * @param Response $response - * @return Api|MockObject + * @return Api&MockObject */ public function createApiMockObject(Response $response) { @@ -26,7 +27,7 @@ public function createApiMockObject(Response $response) /** * @param Response[] $responses - * @return MockObject|Api + * @return Api&MockObject */ public function createApiMultiMockObject(array $responses) { @@ -34,7 +35,7 @@ public function createApiMultiMockObject(array $responses) return $this ->getMockBuilder(Api::class) - ->addMethods([]) + ->onlyMethods([]) ->setConstructorArgs([ '', new Client([ @@ -45,10 +46,10 @@ public function createApiMultiMockObject(array $responses) } /** - * @template T + * @template T of ClientInterface * @param class-string $className * @param Response $response - * @return MockObject|T + * @return T&MockObject */ public function createClientMockObject(string $className, Response $response) { @@ -56,10 +57,10 @@ public function createClientMockObject(string $className, Response $response) } /** - * @template T + * @template T of ClientInterface * @param class-string $className * @param Response[] $responses - * @return MockObject|T + * @return T&MockObject */ public function createClientMultiMockObject(string $className, array $responses) { @@ -67,14 +68,14 @@ public function createClientMultiMockObject(string $className, array $responses) return $this ->getMockBuilder($className) - ->addMethods([]) + ->onlyMethods([]) ->setConstructorArgs([$api]) ->getMock(); } /** * @param Response[] $responses - * @return MockObject|PaginationClient + * @return PaginationClient&MockObject * @throws ReflectionException */ public function createPaginationClientMockObject(array $responses) @@ -83,9 +84,9 @@ public function createPaginationClientMockObject(array $responses) $stub = $this ->getMockBuilder(PaginationClient::class) - ->addMethods([]) + ->onlyMethods([]) ->setConstructorArgs([$api]) - ->getMockForAbstractClass(); + ->getMock(); $this->setProtectedProperty($stub, 'resource', 'resource');