Skip to content

Commit

Permalink
fixup! Use setup & teardown once for class, refactor methods to stati…
Browse files Browse the repository at this point in the history
…c where applicable
  • Loading branch information
foglcz committed Apr 13, 2018
1 parent 81f858f commit cf93778
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
24 changes: 12 additions & 12 deletions tests/integration/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

class IntegrationTestCase extends TestCase
{
protected function markAsSkippedIfMatejIsNotAvailable(): void
protected static function markAsSkippedIfMatejIsNotAvailable(): void
{
if (!getenv('MATEJ_TEST_ACCOUNTID')) {
$this->markTestSkipped('Environment variable MATEJ_TEST_ACCOUNTID has to be defined');
self::markTestSkipped('Environment variable MATEJ_TEST_ACCOUNTID has to be defined');
}

if (!getenv('MATEJ_TEST_APIKEY')) {
$this->markTestSkipped('Environment variable MATEJ_TEST_APIKEY has to be defined');
self::markTestSkipped('Environment variable MATEJ_TEST_APIKEY has to be defined');
}
}

protected function createMatejInstance(): Matej
protected static function createMatejInstance(): Matej
{
$this->markAsSkippedIfMatejIsNotAvailable();
self::markAsSkippedIfMatejIsNotAvailable();

$instance = new Matej(getenv('MATEJ_TEST_ACCOUNTID'), getenv('MATEJ_TEST_APIKEY'));

Expand All @@ -32,21 +32,21 @@ protected function createMatejInstance(): Matej
return $instance;
}

protected function assertResponseCommandStatuses(Response $response, ...$expectedCommandStatuses): void
protected static function assertResponseCommandStatuses(Response $response, ...$expectedCommandStatuses): void
{
$this->assertSame(count($expectedCommandStatuses), $response->getNumberOfCommands());
$this->assertSame(count(array_intersect($expectedCommandStatuses, ['OK'])), $response->getNumberOfSuccessfulCommands());
$this->assertSame(count(array_intersect($expectedCommandStatuses, ['ERROR'])), $response->getNumberOfFailedCommands());
$this->assertSame(count(array_intersect($expectedCommandStatuses, ['SKIPPED'])), $response->getNumberOfSkippedCommands());
self::assertSame(count($expectedCommandStatuses), $response->getNumberOfCommands());
self::assertSame(count(array_intersect($expectedCommandStatuses, ['OK'])), $response->getNumberOfSuccessfulCommands());
self::assertSame(count(array_intersect($expectedCommandStatuses, ['ERROR'])), $response->getNumberOfFailedCommands());
self::assertSame(count(array_intersect($expectedCommandStatuses, ['SKIPPED'])), $response->getNumberOfSkippedCommands());

$commandResponses = $response->getCommandResponses();
foreach ($expectedCommandStatuses as $key => $expectedStatus) {
$this->assertSame($expectedStatus, $commandResponses[$key]->getStatus());
self::assertSame($expectedStatus, $commandResponses[$key]->getStatus());
}
}

/** @return string[] */
protected function generateOkStatuses(int $amount): array
protected static function generateOkStatuses(int $amount): array
{
$data = explode(',', str_repeat('OK,', $amount));
array_pop($data);
Expand Down
27 changes: 16 additions & 11 deletions tests/integration/RequestBuilder/EventsRequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
*/
class EventsRequestBuilderTest extends IntegrationTestCase
{
protected function setup(): void
public static function setUpBeforeClass(): void
{
$builder = $this->createMatejInstance()->request()->setupItemProperties();
$request = self::createMatejInstance()->request()->setupItemProperties();

$this->buildAndSendPropertySetupRequest($builder);
self::addPropertiesToPropertySetupRequest($request);

$request->send();
}

protected function tearDown(): void
public static function tearDownAfterClass(): void
{
$builder = $this->createMatejInstance()->request()->deleteItemProperties();
$request = self::createMatejInstance()->request()->deleteItemProperties();

self::addPropertiesToPropertySetupRequest($request);

$this->buildAndSendPropertySetupRequest($builder);
$request->send();
}

/** @test */
Expand Down Expand Up @@ -68,11 +72,12 @@ public function shouldExecuteInteractionAndUserMergeAndItemPropertyCommands(): v
$this->assertResponseCommandStatuses($response, ...$this->generateOkStatuses(10));
}

private function buildAndSendPropertySetupRequest(ItemPropertiesSetupRequestBuilder $builder): void
private static function addPropertiesToPropertySetupRequest(ItemPropertiesSetupRequestBuilder $builder): void
{
$builder->addProperty(ItemPropertySetup::string('test_property_a'))
->addProperty(ItemPropertySetup::string('test_property_b'))
->addProperty(ItemPropertySetup::string('test_property_c'))
->send();
$builder->addProperties([
ItemPropertySetup::string('test_property_a'),
ItemPropertySetup::string('test_property_b'),
ItemPropertySetup::string('test_property_c'),
]);
}
}

0 comments on commit cf93778

Please sign in to comment.