Skip to content
Merged
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
36 changes: 0 additions & 36 deletions .phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,6 @@ parameters:
treatPhpDocTypesAsCertain: false

ignoreErrors:
-
message: "#^Constructor of class Art4\\\\JsonApiClient\\\\V1\\\\ResourceNull has an unused parameter \\$data\\.$#"
count: 1
path: src/V1/ResourceNull.php
# parameter is required by Art4\JsonApiClient\Element

-
message: "#^Constructor of class Art4\\\\JsonApiClient\\\\V1\\\\ResourceNull has an unused parameter \\$manager\\.$#"
count: 1
path: src/V1/ResourceNull.php
# parameter is required by Art4\JsonApiClient\Element

-
message: "#^Constructor of class Art4\\\\JsonApiClient\\\\V1\\\\ResourceNull has an unused parameter \\$parent\\.$#"
count: 1
path: src/V1/ResourceNull.php
# parameter is required by Art4\JsonApiClient\Element

-
message: "#^Constructor of an anonymous class has an unused parameter \\$data\\.$#"
count: 1
path: tests/BC/ElementTest.php
# parameter is required by Art4\JsonApiClient\Element

-
message: "#^Constructor of an anonymous class has an unused parameter \\$manager\\.$#"
count: 1
path: tests/BC/ElementTest.php
# parameter is required by Art4\JsonApiClient\Element

-
message: "#^Constructor of an anonymous class has an unused parameter \\$parent\\.$#"
count: 1
path: tests/BC/ElementTest.php
# parameter is required by Art4\JsonApiClient\Element

-
message: "#^Parameter \\#1 \\$string of class Art4\\\\JsonApiClient\\\\Input\\\\RequestStringInput constructor expects string, mixed given\\.$#"
count: 1
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^10.4"
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.4 || ^11.0 || ^12.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions tests/BC/AccessableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getKeys()
}
};

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Accessable::class, $class);
}
}
1 change: 1 addition & 0 deletions tests/BC/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function testBcForElementInterface(): void
public function __construct($data, Manager $manager, Accessable $parent) {}
};

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Element::class, $class);
}
}
1 change: 1 addition & 0 deletions tests/BC/Exception/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function testBcForExceptionInterface(): void
*/
$class = new class implements Exception {};

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Exception::class, $class);
}
}
1 change: 1 addition & 0 deletions tests/BC/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function make($name, array $args = [])
}
};

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Factory::class, $class);
}
}
3 changes: 1 addition & 2 deletions tests/BC/Input/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function testBcForInputInterface(): void
* This should be a native PH stdClass object, so Manager could
* iterate over all public attributes
*
* @throws \Art4\JsonApiClient\Exception\InputException if something went wrong with the input
*
* @return \stdClass
*/
public function getAsObject()
Expand All @@ -40,6 +38,7 @@ public function getAsObject()
}
};

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Input::class, $class);
}
}
1 change: 1 addition & 0 deletions tests/BC/Input/RequestInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function testBcForRequestInputInterface(): void
*/
$class = new class implements RequestInput {};

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(RequestInput::class, $class);
}
}
4 changes: 1 addition & 3 deletions tests/BC/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public function testBcForManagerInterface(): void
*
* @param \Art4\JsonApiClient\Input\Input $input
*
* @throws \Art4\JsonApiClient\Exception\InputException If $input contains invalid JSON API
* @throws \Art4\JsonApiClient\Exception\ValidationException If $input contains invalid JSON API
*
* @return \Art4\JsonApiClient\Accessable
*/
public function parse(Input $input)
Expand Down Expand Up @@ -64,6 +61,7 @@ public function getParam($key, $default)
}
};

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Manager::class, $class);
}
}
1 change: 1 addition & 0 deletions tests/BC/Serializer/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function serialize(Accessable $data)
}
};

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Serializer::class, $class);
}
}
4 changes: 2 additions & 2 deletions tests/Fixtures/HelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function setUpManagerMock(): void

$this->manager->expects($this->any())
->method('getFactory')
->will($this->returnValue($factory));
->willReturn($factory);

$this->manager->expects($this->any())
->method('getParam')
Expand All @@ -177,7 +177,7 @@ public function setUpManagerMock(): void
/**
* returns a json string from a file
*/
protected function getJsonString(mixed $filename): string
protected function getJsonString(string $filename): string
{
return strval(file_get_contents(__DIR__ . '/../files/' . $filename));
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Fixtures/V1Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Art4\JsonApiClient\Tests\Fixtures;

use Art4\JsonApiClient\Factory as FactoryInterface;
use PHPUnit\Framework\MockObject\MockBuilder;
use PHPUnit\Framework\TestCase;

final class V1Factory implements FactoryInterface
Expand All @@ -33,11 +34,9 @@ public function __construct(TestCase $testcase)
*/
public function make($name, array $args = [])
{
return $this->testcase->getMockBuilder(AccessableElement::class)
return (new MockBuilder($this->testcase, AccessableElement::class))
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
->getMock();
}
}
1 change: 1 addition & 0 deletions tests/Unit/Input/RequestStringInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function testGetAsObjectFromStringReturnsObject(): void
{
$input = new RequestStringInput('{}');

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(\stdClass::class, $input->getAsObject());
}

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Input/ResponseStringInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function testGetAsObjectFromStringReturnsObject(): void
{
$input = new ResponseStringInput('{}');

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(\stdClass::class, $input->getAsObject());
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Serializer/ArraySerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public function testSerialize(): void
$object2 = new \stdClass();

$data = $this->createMock(Accessable::class);
$data->method('get')->will($this->returnValueMap([
$data->method('get')->willReturnMap([
['AccessObject', $object1],
['object', $object2],
['array', []],
['string', 'string'],
['integer', 1],
['boolean', true],
['null', null],
]));
]);
$data->method('getKeys')->willReturn([
'AccessObject',
'object',
Expand Down Expand Up @@ -64,14 +64,14 @@ public function testRecursiveSerialize(): void
$stdObject->key = 'value';

$object1 = $this->createMock(Accessable::class);
$object1->method('get')->will($this->returnValueMap([
$object1->method('get')->willReturnMap([
['object', $stdObject],
['array', []],
['string', 'string'],
['integer', 1],
['boolean', true],
['null', null],
]));
]);
$object1->method('getKeys')->willReturn([
'object',
'array',
Expand All @@ -82,9 +82,9 @@ public function testRecursiveSerialize(): void
]);

$data = $this->createMock(Accessable::class);
$data->method('get')->will($this->returnValueMap([
$data->method('get')->willReturnMap([
['AccessObject', $object1],
]));
]);
$data->method('getKeys')->willReturn([
'AccessObject',
]);
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/V1/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function testCreateWithObject(): void
$this->parent
);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Accessable::class, $attributes);
$this->assertTrue($attributes->has('object'));
$this->assertIsObject($attributes->get('object'));
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/V1/DocumentLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setUp(): void
$this->parent->expects($this->any())
->method('has')
->with('data')
->will($this->returnValue(true));
->willReturn(true);
}

/**
Expand All @@ -59,6 +59,7 @@ public function testOnlySelfRelatedPaginationPropertiesExists(): void

$link = new DocumentLink($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Accessable::class, $link);
$this->assertSame([
'self',
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/V1/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function testCreateWithObjectReturnsSelf(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Accessable::class, $document);
$this->assertSame($document->getKeys(), ['meta']);
$this->assertTrue($document->has('meta'));
Expand Down Expand Up @@ -74,6 +76,7 @@ public function testCreateWithAllPossibleValues(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertSame($document->getKeys(), ['data', 'meta', 'included', 'jsonapi', 'links']);
$this->assertTrue($document->has('data'));
Expand Down Expand Up @@ -135,6 +138,7 @@ public function testCreateDataWithResourceIdentifier(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('data'));

Expand All @@ -156,6 +160,7 @@ public function testCreateDataWithResourceIdentifierAndMeta(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);

$this->assertTrue($document->has('data'));
Expand All @@ -178,6 +183,7 @@ public function testCreateDataWithResourceItem(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('data'));

Expand All @@ -198,6 +204,7 @@ public function testCreateDataWithResourceCollectionIdentifiers(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('data'));

Expand All @@ -220,6 +227,7 @@ public function testCreateDataWithResourceCollectionResources(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('data'));

Expand All @@ -240,6 +248,7 @@ public function testCreateWithDataproviderInValue(mixed $input): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('data'));

Expand All @@ -257,6 +266,7 @@ public function testCreateWithDataproviderInValue(mixed $input): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('data'));

Expand Down Expand Up @@ -289,6 +299,7 @@ public function testCreateWithErrorsArray(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertSame($document->getKeys(), ['errors']);
$this->assertTrue($document->has('errors'));
Expand Down Expand Up @@ -323,6 +334,7 @@ public function testCreateWithMetaObject(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('meta'));

Expand All @@ -341,6 +353,7 @@ public function testCreateWithJsonapiObject(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('jsonapi'));

Expand All @@ -359,6 +372,7 @@ public function testCreateWithLinkObject(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('links'));

Expand All @@ -383,6 +397,7 @@ public function testCreateWithIncludedObjects(): void

$document = new Document($object, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Document::class, $document);
$this->assertTrue($document->has('included'));

Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/V1/ErrorCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function testCreate(): void

$collection = new ErrorCollection($errors, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(ErrorCollection::class, $collection);
/** @phpstan-ignore-next-line */
$this->assertInstanceOf(Accessable::class, $collection);

$this->assertSame($collection->getKeys(), [0, 1]);
Expand Down Expand Up @@ -94,6 +96,7 @@ public function testGetErrorWithEmptyCollectionThrowsException(): void

$collection = new ErrorCollection($errors, $this->manager, $this->parent);

/** @phpstan-ignore-next-line */
$this->assertInstanceOf(ErrorCollection::class, $collection);

$this->assertFalse($collection->has(1));
Expand Down
Loading