Skip to content

Commit

Permalink
replace dataProvider annotations with DataProvider attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Nov 28, 2023
1 parent 8a18b4c commit 63e764a
Show file tree
Hide file tree
Showing 28 changed files with 83 additions and 214 deletions.
6 changes: 0 additions & 6 deletions tests/Functional/DotNotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class DotNotationTest extends TestCase
{
use HelperTrait;

/**
* @test
*/
public function testCompleteResourceObjectWithMultipleRelationships(): void
{
$manager = new ErrorAbortManager(new Factory());
Expand Down Expand Up @@ -189,9 +186,6 @@ public function testCompleteResourceObjectWithMultipleRelationships(): void
$this->assertSame('http://example.com/comments/12', $document->get('included.2.links.self'));
}

/**
* @test
*/
public function testGetNotExistentValueThrowsException(): void
{
$manager = new ErrorAbortManager(new Factory());
Expand Down
6 changes: 0 additions & 6 deletions tests/Functional/ErrorParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class ErrorParsingTest extends TestCase
{
use HelperTrait;

/**
* @test
*/
public function testParseErrors(): void
{
$string = $this->getJsonString('09_errors.json');
Expand Down Expand Up @@ -89,9 +86,6 @@ public function testParseErrors(): void
$this->assertFalse($errors->has('3'));
}

/**
* @test
*/
public function testParseErrorWithLinks(): void
{
$string = $this->getJsonString('10_error_with_links.json');
Expand Down
44 changes: 2 additions & 42 deletions tests/Functional/ParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Art4\JsonApiClient\Manager\ErrorAbortManager;
use Art4\JsonApiClient\Tests\Fixtures\HelperTrait;
use Art4\JsonApiClient\V1\Factory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class ParsingTest extends TestCase
Expand All @@ -38,9 +39,7 @@ public static function createParserProvider(): array
];
}

/**
* @dataProvider createParserProvider
*/
#[DataProvider('createParserProvider')]
public function testParseSimpleResourceWithDifferentParser(callable $parser): void
{
$string = $this->getJsonString('01_simple_resource.json');
Expand All @@ -67,9 +66,6 @@ public function testParseSimpleResourceWithDifferentParser(callable $parser): vo
$this->assertInstanceOf('Art4\JsonApiClient\V1\RelationshipCollection', $resource->get('relationships'));
}

/**
* @test
*/
public function testParseSimpleResourceIdentifier(): void
{
$string = $this->getJsonString('02_simple_resource_identifier.json');
Expand All @@ -91,9 +87,6 @@ public function testParseSimpleResourceIdentifier(): void
$this->assertSame($resource->get('id'), '1');
}

/**
* @test
*/
public function testParseResourceObject(): void
{
$string = $this->getJsonString('03_resource_object.json');
Expand Down Expand Up @@ -159,9 +152,6 @@ public function testParseResourceObject(): void
$this->assertSame($data->get('id'), '9');
}

/**
* @test
*/
public function testParseCompleteResourceObjectWithMultipleRelationships(): void
{
$string = $this->getJsonString('04_complete_document_with_multiple_relationships.json');
Expand Down Expand Up @@ -355,9 +345,6 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void
$this->assertSame($links->get('self'), 'http://example.com/comments/12');
}

/**
* @test
*/
public function testParsePaginationExample(): void
{
$string = $this->getJsonString('06_pagination_example.json');
Expand Down Expand Up @@ -409,9 +396,6 @@ public function testParsePaginationExample(): void
$this->assertSame($links->get('last'), 'http://example.com/articles?page[number]=13&page[size]=1');
}

/**
* @test
*/
public function testParseRelationshipExample(): void
{
$string = $this->getJsonString('07_relationship_example_without_data.json');
Expand Down Expand Up @@ -475,9 +459,6 @@ public function testParseRelationshipExample(): void
$this->assertSame($document->get('data.0.relationships.comments.links.related.meta.count'), 10);
}

/**
* @test
*/
public function testParseObjectLinksExample(): void
{
$string = $this->getJsonString('08_object_links.json');
Expand Down Expand Up @@ -518,9 +499,6 @@ public function testParseObjectLinksExample(): void
$this->assertSame('bar', $document->get('jsonapi.meta.foo'));
}

/**
* @test
*/
public function testParseResourceIdentifierWithMeta(): void
{
$string = $this->getJsonString('11_resource_identifier_with_meta.json');
Expand All @@ -544,9 +522,6 @@ public function testParseResourceIdentifierWithMeta(): void
$this->assertSame($resource->get('id'), '2');
}

/**
* @test
*/
public function testParseNullResource(): void
{
$string = $this->getJsonString('12_null_resource.json');
Expand All @@ -565,9 +540,6 @@ public function testParseNullResource(): void
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceNull', $resource);
}

/**
* @test
*/
public function testParseResourceIdentifierCollectionWithMeta(): void
{
$string = $this->getJsonString('13_collection_with_resource_identifier_with_meta.json');
Expand Down Expand Up @@ -602,9 +574,6 @@ public function testParseResourceIdentifierCollectionWithMeta(): void
$this->assertSame($resource1->get('id'), '2');
}

/**
* @test
*/
public function testParseCreateResourceWithoutId(): void
{
$string = $this->getJsonString('14_create_resource_without_id.json');
Expand All @@ -614,9 +583,6 @@ public function testParseCreateResourceWithoutId(): void
$this->assertSame(['data'], $document->getKeys());
}

/**
* @test
*/
public function testParseCreateShortResourceWithoutId(): void
{
$string = $this->getJsonString('15_create_resource_without_id.json');
Expand All @@ -626,19 +592,13 @@ public function testParseCreateShortResourceWithoutId(): void
$this->assertSame(['data'], $document->getKeys());
}

/**
* @test
*/
public function testExceptionIfIdIsNotString(): void
{
$this->expectException(\Art4\JsonApiClient\Exception\ValidationException::class);
$string = $this->getJsonString('16_type_and_id_as_integer.json');
$document = Parser::parseResponseString($string);
}

/**
* @test
*/
public function testParseLinksInRelationshipsCorrectly(): void
{
$string = $this->getJsonString('17_relationship_links.json');
Expand Down
5 changes: 2 additions & 3 deletions tests/Functional/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Art4\JsonApiClient\Tests\Fixtures\HelperTrait;
use Art4\JsonApiClient\V1\Factory;
use Exception;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class SerializerTest extends TestCase
Expand Down Expand Up @@ -61,9 +62,7 @@ public static function jsonapiDataProvider(): array
return $files;
}

/**
* @dataProvider jsonapiDataProvider
*/
#[DataProvider('jsonapiDataProvider')]
public function testParseJsonapiDataWithErrorAbortManager(string $filename, bool $isRequest): void
{
$manager = new ErrorAbortManager(new Factory());
Expand Down
9 changes: 3 additions & 6 deletions tests/Unit/Helper/AccessableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
use Art4\JsonApiClient\Exception\AccessException;
use Art4\JsonApiClient\Tests\Fixtures\AccessableTraitMock;
use Art4\JsonApiClient\Tests\Fixtures\HelperTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class AccessableTraitTest extends TestCase
{
use HelperTrait;

/**
* @dataProvider jsonValuesProviderWithoutStringAndInt
*/
#[DataProvider('jsonValuesProviderWithoutStringAndInt')]
public function testHasWithInvalidKeyTypeTriggersDeprecationError(mixed $key): void
{
$resource = new AccessableTraitMock();
Expand All @@ -41,9 +40,7 @@ function ($errno, $errstr) use ($key): bool {
$resource->has($key);
}

/**
* @dataProvider jsonValuesProviderWithoutStringAndInt
*/
#[DataProvider('jsonValuesProviderWithoutStringAndInt')]
public function testGetWithInvalidKeyTypeTriggersDeprecationError(mixed $key): void
{
$resource = new AccessableTraitMock();
Expand Down
9 changes: 3 additions & 6 deletions tests/Unit/Input/RequestStringInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Art4\JsonApiClient\Exception\InputException;
use Art4\JsonApiClient\Input\RequestStringInput;
use Art4\JsonApiClient\Tests\Fixtures\HelperTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class RequestStringInputTest extends TestCase
Expand All @@ -24,9 +25,7 @@ public function testGetAsObjectFromStringReturnsObject(): void
$this->assertInstanceOf(\stdClass::class, $input->getAsObject());
}

/**
* @dataProvider jsonValuesProviderWithoutString
*/
#[DataProvider('jsonValuesProviderWithoutString')]
public function testCreateWithoutStringThrowsException(mixed $input): void
{
$this->expectException(InputException::class);
Expand All @@ -36,9 +35,7 @@ public function testCreateWithoutStringThrowsException(mixed $input): void
new RequestStringInput($input);
}

/**
* @dataProvider jsonValuesAsStringProviderWithoutObject
*/
#[DataProvider('jsonValuesAsStringProviderWithoutObject')]
public function testGetAsObjectWithInvalidStringsThrowsException(string $input): void
{
$input = new RequestStringInput($input);
Expand Down
9 changes: 3 additions & 6 deletions tests/Unit/Input/ResponseStringInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Art4\JsonApiClient\Exception\InputException;
use Art4\JsonApiClient\Input\ResponseStringInput;
use Art4\JsonApiClient\Tests\Fixtures\HelperTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class ResponseStringInputTest extends TestCase
Expand All @@ -24,9 +25,7 @@ public function testGetAsObjectFromStringReturnsObject(): void
$this->assertInstanceOf(\stdClass::class, $input->getAsObject());
}

/**
* @dataProvider jsonValuesProviderWithoutString
*/
#[DataProvider('jsonValuesProviderWithoutString')]
public function testCreateWithoutStringThrowsException(mixed $input): void
{
$this->expectException(InputException::class);
Expand All @@ -36,9 +35,7 @@ public function testCreateWithoutStringThrowsException(mixed $input): void
new ResponseStringInput($input);
}

/**
* @dataProvider jsonValuesAsStringProviderWithoutObject
*/
#[DataProvider('jsonValuesAsStringProviderWithoutObject')]
public function testGetAsObjectWithInvalidStringsThrowsException(string $input): void
{
$input = new ResponseStringInput($input);
Expand Down
6 changes: 0 additions & 6 deletions tests/Unit/Manager/ErrorAbortManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

class ErrorAbortManagerTest extends TestCase
{
/**
* @test
*/
public function testCreateWithConstructorReturnsSelf(): void
{
$factory = $this->createMock(Factory::class);
Expand All @@ -25,9 +22,6 @@ public function testCreateWithConstructorReturnsSelf(): void
$this->assertSame($factory, $manager->getFactory());
}

/**
* @test
*/
public function testGetParamReturnsDefault(): void
{
$factory = $this->createMock(Factory::class);
Expand Down
8 changes: 2 additions & 6 deletions tests/Unit/V1/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Art4\JsonApiClient\Exception\ValidationException;
use Art4\JsonApiClient\Tests\Fixtures\HelperTrait;
use Art4\JsonApiClient\V1\Attributes;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class AttributesTest extends TestCase
Expand Down Expand Up @@ -80,9 +81,7 @@ public function testCreateWithObject(): void
], $attributes->getKeys());
}

/**
* @dataProvider jsonValuesProviderWithoutObject
*/
#[DataProvider('jsonValuesProviderWithoutObject')]
public function testCreateWithDataProvider(mixed $input): void
{
$this->expectException(ValidationException::class);
Expand Down Expand Up @@ -186,9 +185,6 @@ public function testCreateWithLinksPropertyThrowsException(): void
);
}

/**
* @test
*/
public function testGetOnANonExistingKeyThrowsException(): void
{
$object = new \stdClass();
Expand Down
Loading

0 comments on commit 63e764a

Please sign in to comment.