Skip to content

Commit

Permalink
Fix failing intergration test (RAD-1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
foglcz committed Apr 17, 2018
1 parent 3948c9b commit 020b94d
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 21 deletions.
12 changes: 6 additions & 6 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 @@ -46,7 +46,7 @@ protected function assertResponseCommandStatuses(Response $response, ...$expecte
}

/** @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
2 changes: 1 addition & 1 deletion tests/integration/MatejTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function shouldReceiveRequestIdInResponse(): void
{
$requestId = uniqid('integration-test-php-client-request-id');

$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->sorting(Sorting::create('integration-test-php-client-user-id-A', ['itemA', 'itemB']))
->setRequestId($requestId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function shouldThrowExceptionWhenSendingBlankRequest(): void
$this->expectException(LogicException::class);
$this->expectExceptionMessage('At least one command must be added to the builder before sending the request');

$this->createMatejInstance()
static::createMatejInstance()
->request()
->campaign()
->send();
Expand All @@ -27,7 +27,7 @@ public function shouldThrowExceptionWhenSendingBlankRequest(): void
/** @test */
public function shouldExecuteRecommendationAndSortingCommands(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->campaign()
->addRecommendation($this->createRecommendationCommand('a'))
Expand Down
33 changes: 31 additions & 2 deletions tests/integration/RequestBuilder/EventsRequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,40 @@
use Lmc\Matej\IntegrationTests\IntegrationTestCase;
use Lmc\Matej\Model\Command\Interaction;
use Lmc\Matej\Model\Command\ItemProperty;
use Lmc\Matej\Model\Command\ItemPropertySetup;
use Lmc\Matej\Model\Command\UserMerge;
use Lmc\Matej\RequestBuilder\ItemPropertiesSetupRequestBuilder;

/**
* @covers \Lmc\Matej\RequestBuilder\EventsRequestBuilder
*/
class EventsRequestBuilderTest extends IntegrationTestCase
{
public static function setUpBeforeClass(): void
{
$request = self::createMatejInstance()->request()->setupItemProperties();

self::addPropertiesToPropertySetupRequest($request);

$request->send();
}

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

self::addPropertiesToPropertySetupRequest($request);

$request->send();
}

/** @test */
public function shouldThrowExceptionWhenSendingBlankRequest(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('At least one command must be added to the builder before sending the request');

$this->createMatejInstance()
static::createMatejInstance()
->request()
->events()
->send();
Expand All @@ -28,7 +48,7 @@ public function shouldThrowExceptionWhenSendingBlankRequest(): void
/** @test */
public function shouldExecuteInteractionAndUserMergeAndItemPropertyCommands(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->events()
->addInteraction(Interaction::bookmark('user-a', 'item-a'))
Expand All @@ -51,4 +71,13 @@ public function shouldExecuteInteractionAndUserMergeAndItemPropertyCommands(): v

$this->assertResponseCommandStatuses($response, ...$this->generateOkStatuses(10));
}

private static function addPropertiesToPropertySetupRequest(ItemPropertiesSetupRequestBuilder $builder): void
{
$builder->addProperties([
ItemPropertySetup::string('test_property_a'),
ItemPropertySetup::string('test_property_b'),
ItemPropertySetup::string('test_property_c'),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ItemPropertiesGetRequestBuilderTest extends IntegrationTestCase
/** @test */
public function shouldGetListOfPropertiesFromMatej(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->getItemProperties()
->send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public function shouldThrowExceptionWhenSendingBlankRequests(ItemPropertiesSetup
public function provideBuilders(): array
{
return [
'setup properties' => [$this->createMatejInstance()->request()->setupItemProperties()],
'delete properties' => [$this->createMatejInstance()->request()->deleteItemProperties()],
'setup properties' => [static::createMatejInstance()->request()->setupItemProperties()],
'delete properties' => [static::createMatejInstance()->request()->deleteItemProperties()],
];
}

/** @test */
public function shouldCreateNewPropertiesInMatej(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->setupItemProperties()
->addProperty(Command\ItemPropertySetup::boolean('test_property_bool'))
Expand All @@ -59,7 +59,7 @@ public function shouldCreateNewPropertiesInMatej(): void
*/
public function shouldDeleteCreatedPropertiesFromMatej(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->deleteItemProperties()
->addProperty(Command\ItemPropertySetup::boolean('test_property_bool'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RecommendationRequestBuilderTest extends IntegrationTestCase
/** @test */
public function shouldExecuteRecommendationRequestOnly(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->recommendation($this->createRecommendationCommand('user-a'))
->send();
Expand All @@ -31,7 +31,7 @@ public function shouldExecuteRecommendationRequestOnly(): void
/** @test */
public function shouldExecuteRecommendationRequestWithUserMergeAndInteraction(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->recommendation($this->createRecommendationCommand('user-b'))
->setUserMerge(UserMerge::mergeInto('user-b', 'user-a'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ResetDatabaseRequestBuilderTest extends IntegrationTestCase
/** @test */
public function shouldResetMatejDatabase(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->resetDatabase()
->send();
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/RequestBuilder/SortingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SortingRequestTest extends IntegrationTestCase
/** @test */
public function shouldExecuteSortingRequestOnly(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->sorting(Sorting::create('user-a', ['itemA', 'itemB', 'itemC']))
->send();
Expand All @@ -31,7 +31,7 @@ public function shouldExecuteSortingRequestOnly(): void
/** @test */
public function shouldExecuteSortingRequestWithUserMergeAndInteraction(): void
{
$response = $this->createMatejInstance()
$response = static::createMatejInstance()
->request()
->sorting(Sorting::create('user-b', ['item-a', 'item-b', 'itemC-c']))
->setUserMerge(UserMerge::mergeInto('user-b', 'user-a'))
Expand Down

0 comments on commit 020b94d

Please sign in to comment.