Skip to content

Commit

Permalink
[QA] Add PHPUnit provider with attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
landrok committed Apr 6, 2024
1 parent 6613d68 commit 359568a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
3 changes: 2 additions & 1 deletion tests/ActivityPhp/Server/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function getFailingInstanceScenarios()
* Check that all tests are failing
*
* @dataProvider getFailingInstanceScenarios
* #[DataProvider('getFailingInstanceScenarios')]
*/
public function testFailingInstanceScenarios($data)
{
Expand All @@ -45,7 +46,7 @@ public function testFailingOnNonExistingParameter()
$this->expectException(Exception::class);

$config = new Configuration();

$config->getConfig('https');
}
}
3 changes: 2 additions & 1 deletion tests/ActivityPhp/Server/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public static function getAcceptHeaderScenarios()
'application/pdf',
'application/json'
], false ], # Refused (array input)

];
}

/**
* @dataProvider getAcceptHeaderScenarios
* #[DataProvider('getAcceptHeaderScenarios')]
*/
public function testAcceptHeaderScenarios($input, $expected)
{
Expand Down
1 change: 1 addition & 0 deletions tests/ActivityPhp/Server/OutboxPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static function getOutboxPostActivities()
* Check that all response are valid
*
* @dataProvider getOutboxPostActivities
* #[DataProvider('getOutboxPostActivities')]
*/
public function testOutboxPostActivities($payload, $accept = 'application/activity+json', $code = 201)
{
Expand Down
13 changes: 8 additions & 5 deletions tests/ActivityPhp/Server/WebFingerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function getSuccessScenarios()
]
]
];

# handle / method / expected
return [
['bob@localhost:8000', 'toArray', $sample ], # toArray()
Expand Down Expand Up @@ -80,6 +80,7 @@ public static function getFailingScenarios()
* Check that all response are valid
*
* @dataProvider getSuccessScenarios
* #[DataProvider('getSuccessScenarios')]
*/
public function testSuccessScenarios($handle, $method, $expected)
{
Expand All @@ -97,7 +98,7 @@ public function testSuccessScenarios($handle, $method, $expected)

$webfinger = $server->actor($handle)->webfinger();

// Assert
// Assert
$this->assertEquals(
$expected,
$webfinger->$method()
Expand All @@ -108,6 +109,7 @@ public function testSuccessScenarios($handle, $method, $expected)
* Check that all tests are failing
*
* @dataProvider getFailingScenarios
* #[DataProvider('getFailingScenarios')]
*/
public function testFailingScenarios($handle, $method, $expected)
{
Expand All @@ -125,7 +127,7 @@ public function testFailingScenarios($handle, $method, $expected)
]
]);



$webfinger = $server->actor($handle)->webfinger();
}
Expand Down Expand Up @@ -192,6 +194,7 @@ public static function getFailingInstanceScenarios()
* Check that all tests are failing
*
* @dataProvider getFailingInstanceScenarios
* #[DataProvider('getFailingInstanceScenarios')]
*/
public function testFailingInstanceScenarios($data)
{
Expand All @@ -201,7 +204,7 @@ public function testFailingInstanceScenarios($data)
}

/**
* Get profile id can return null if webfinger is used for an
* Get profile id can return null if webfinger is used for an
* implementation that does not support ActivityPhp
*/
public function testEmptyProfileId()
Expand All @@ -222,7 +225,7 @@ public function testEmptyProfileId()

$webfinger = new WebFinger($data);

// Assert
// Assert
$this->assertEquals(
null,
$webfinger->getProfileId()
Expand Down
2 changes: 2 additions & 0 deletions tests/ActivityPhp/Type/AttributeFormatValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ public static function getExceptionScenarios()
* It checks that getter is working well too.
*
* @dataProvider getValidAttributesScenarios
* #[DataProvider('getValidAttributesScenarios')]
*/
public function testValidAttributesScenarios($attr, $type, $value)
{
Expand Down Expand Up @@ -1398,6 +1399,7 @@ public function testValidAttributesScenarios($attr, $type, $value)

/**
* @dataProvider getExceptionScenarios
* #[DataProvider('getExceptionScenarios')]
*/
public function testExceptionScenarios($attr, $type, $value)
{
Expand Down
41 changes: 21 additions & 20 deletions tests/ActivityPhp/Type/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ public static function getShortTypes()

/**
* Check that all core objects have a correct type property.
*
*
* @dataProvider getShortTypes
* #[DataProvider('getShortTypes')]
*/
public function testShortTypesInstanciation($type)
{
$class = Type::create($type, ['name' => strtolower($type)]);

// Assert affectation
$this->assertEquals(
strtolower($type),
Expand Down Expand Up @@ -114,7 +115,7 @@ public function testUndefinedType()

/**
* Scenario for a custom validator
*
*
* - Add a validator in the pool for 'customProperty' attribute
* - Create a type with this property and affect a correct value
*/
Expand All @@ -123,7 +124,7 @@ public function testCustomValidatorSuccess()
Type::add('MyCustomType', MyCustomType::class);
Type::addValidator('customProperty', MyCustomValidator::class);
$type = Type::create(
'MyCustomType',
'MyCustomType',
['customProperty' => 'My value']
);

Expand All @@ -135,7 +136,7 @@ public function testCustomValidatorSuccess()
}

/**
* Scenario for instanciating a Type with a single array parameter
* Scenario for instanciating a Type with a single array parameter
*/
public function testShortCallSuccess()
{
Expand All @@ -149,7 +150,7 @@ public function testShortCallSuccess()
'Note',
$type->type
);

// Assert another property
$this->assertEquals(
'http://example.org/missing-type',
Expand All @@ -158,7 +159,7 @@ public function testShortCallSuccess()
}

/**
* Scenario for instanciating a Type with a single array parameter
* Scenario for instanciating a Type with a single array parameter
* for a failing value (missing type property)
*/
public function testShortCallFailing()
Expand All @@ -184,7 +185,7 @@ public function testShortCallFailingIntGiven()
}

/**
* Scenario for a custom classes and custom validator with an
* Scenario for a custom classes and custom validator with an
* failing value
*/
public function testCustomValidatorFailing()
Expand All @@ -193,22 +194,22 @@ public function testCustomValidatorFailing()

Type::addValidator('customProperty', MyCustomValidator::class);
$type = Type::create(
'MyCustomType',
'MyCustomType',
['customProperty' => 'Bad value']
);
}

/**
* Scenario for a custom type
*
*
* - Add a Type in the pool with 'Person' name
* - Instanciate and sets customType value
* - Instanciate and sets customType value
*/
public function testCustomTypeSuccess()
{
Type::add('Person', MyCustomType::class);
$type = Type::create(
'Person',
'Person',
['customProperty' => 'My value']
);

Expand Down Expand Up @@ -240,7 +241,7 @@ public function testCopy()
]);

$copy = $original->copy();

// Assert type are equals
$this->assertEquals(
$original->type,
Expand All @@ -252,21 +253,21 @@ public function testCopy()
$original->toArray(),
$copy->toArray()
);

// Change a value
$copy->id = 'http://example.org/copy-id';

// Change is ok for the copy
$this->assertEquals(
'http://example.org/copy-id',
$copy->id
);
);

// Assert original is not affected
$this->assertEquals(
'http://example.org/original-id',
$original->id
);
);
}

/**
Expand All @@ -287,13 +288,13 @@ public function testCopyChaining()
$this->assertEquals(
'http://example.org/copy-id',
$copy->id
);
);

// Assert original is not affected
$this->assertEquals(
'http://example.org/original-id',
$original->id
);
);
}

/**
Expand All @@ -308,7 +309,7 @@ public function testFromJson()
$this->assertEquals(
$json,
$note->toJson()
);
);
}

/**
Expand All @@ -328,7 +329,7 @@ public function testFromJsonMalformedJsonString()
*/
public function testFromJsonNotAnArray()
{
$this->expectException(Exception::class);
$this->expectException(Exception::class);

$json = '"OK"';
$note = Type::fromJson($json);
Expand Down
3 changes: 2 additions & 1 deletion tests/ActivityPhp/Type/TypesTypeAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ public static function getObjectTypeScenarios()
/**
* Check that all core objects have a correct type property.
* It checks that getter is working well too.
*
*
* @dataProvider getObjectTypeScenarios
* #[DataProvider('getObjectTypeScenarios')]
*/
public function testObjectTypeScenarios($type, $attr, $value)
{
Expand Down

0 comments on commit 359568a

Please sign in to comment.