-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Item Properties setup integration test case
- Loading branch information
Showing
2 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Matej\IntegrationTests; | ||
|
||
use Lmc\Matej\Matej; | ||
use Lmc\Matej\TestCase; | ||
|
||
class IntegrationTestCase extends TestCase | ||
{ | ||
/** @before */ | ||
protected function checkIfConfigured(): void | ||
{ | ||
if (!getenv('MATEJ_TEST_ACCOUNTID')) { | ||
$this->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'); | ||
} | ||
} | ||
|
||
protected function createMatejInstance(): Matej | ||
{ | ||
$instance = new Matej(getenv('MATEJ_TEST_ACCOUNTID'), getenv('MATEJ_TEST_APIKEY')); | ||
|
||
if ($baseUrl = getenv('MATEJ_TEST_BASE_URL')) { // intentional assignment | ||
$instance->setBaseUrl($baseUrl); | ||
} | ||
|
||
return $instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Matej\IntegrationTests; | ||
|
||
use Lmc\Matej\Model\Command; | ||
|
||
/** | ||
* @covers \Lmc\Matej\RequestBuilder\ItemPropertiesSetupRequestBuilder | ||
* @covers \Lmc\Matej\RequestBuilder\EventsRequestBuilder | ||
*/ | ||
class ItemPropertiesSetupTest extends IntegrationTestCase | ||
{ | ||
/** | ||
* In Matej's Mongo Worker, this will throw an error, because the property isn't defined. | ||
* The API will however return OK. This is desired behaviour. | ||
* | ||
* @test | ||
*/ | ||
public function shouldExecuteRequestContainingUnknownPropertyButPass(): void | ||
{ | ||
$response = $this->createMatejInstance() | ||
->request() | ||
->events() | ||
->addItemProperty( | ||
Command\ItemProperty::create( | ||
'integration-test-php-clientitem-id', | ||
['integration_test_php_client_property_1' => true, 'integration_test_php_client_property_2' => false] | ||
) | ||
) | ||
->send(); | ||
|
||
$this->assertSame(1, $response->getNumberOfCommands()); | ||
$this->assertSame(1, $response->getNumberOfSuccessfulCommands()); | ||
$this->assertSame(0, $response->getNumberOfFailedCommands()); | ||
$this->assertSame(0, $response->getNumberOfSkippedCommands()); | ||
|
||
$commandResponse = $response->getCommandResponses()[0]; | ||
$this->assertSame('OK', $commandResponse->getStatus()); | ||
$this->assertSame([], $commandResponse->getData()); | ||
$this->assertSame('', $commandResponse->getMessage()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @depends shouldExecuteRequestContainingUnknownPropertyButPass | ||
*/ | ||
public function shouldCreateNewPropertiesInMatej(): void | ||
{ | ||
$response = $this->createMatejInstance() | ||
->request() | ||
->setupItemProperties() | ||
->addProperty(Command\ItemPropertySetup::boolean('integration_test_php_client_bool')) | ||
->addProperty(Command\ItemPropertySetup::double('integration_test_php_client_double')) | ||
->addProperty(Command\ItemPropertySetup::int('integration_test_php_client_int')) | ||
->addProperty(Command\ItemPropertySetup::string('integration_test_php_client_string')) | ||
->addProperties([ | ||
Command\ItemPropertySetup::timestamp('integration_test_php_client_timestamp'), | ||
Command\ItemPropertySetup::set('integration_test_php_client_set'), | ||
]) | ||
->send(); | ||
|
||
$this->assertSame(6, $response->getNumberOfCommands()); | ||
$this->assertSame(6, $response->getNumberOfSuccessfulCommands()); | ||
$this->assertSame(0, $response->getNumberOfFailedCommands()); | ||
$this->assertSame(0, $response->getNumberOfSkippedCommands()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @depends shouldCreateNewPropertiesInMatej | ||
*/ | ||
public function shouldExecuteEventWithJustCreatedProperties(): void | ||
{ | ||
$response = $this->createMatejInstance() | ||
->request() | ||
->events() | ||
->addItemProperty( | ||
Command\ItemProperty::create( | ||
'integration-test-php-clientitem-id', | ||
[ | ||
'integration_test_php_client_bool' => true, | ||
'integration_test_php_client_double' => 0.15, | ||
'integration_test_php_client_int' => 15, | ||
'integration_test_php_client_string' => 'some_string', | ||
'integration_test_php_client_timestamp' => 123456789, | ||
'integration_test_php_client_set' => ['some', 'set'], | ||
] | ||
) | ||
) | ||
->send(); | ||
|
||
$this->assertSame(1, $response->getNumberOfCommands()); | ||
$this->assertSame(1, $response->getNumberOfSuccessfulCommands()); | ||
$this->assertSame(0, $response->getNumberOfFailedCommands()); | ||
$this->assertSame(0, $response->getNumberOfSkippedCommands()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @depends shouldExecuteEventWithJustCreatedProperties | ||
*/ | ||
public function shouldDeleteCreatedPropertiesFromMatej(): void | ||
{ | ||
$response = $this->createMatejInstance() | ||
->request() | ||
->deleteItemProperties() | ||
->addProperty(Command\ItemPropertySetup::boolean('integration_test_php_client_bool')) | ||
->addProperty(Command\ItemPropertySetup::double('integration_test_php_client_double')) | ||
->addProperty(Command\ItemPropertySetup::int('integration_test_php_client_int')) | ||
->addProperty(Command\ItemPropertySetup::string('integration_test_php_client_string')) | ||
->addProperties([ | ||
Command\ItemPropertySetup::timestamp('integration_test_php_client_timestamp'), | ||
Command\ItemPropertySetup::set('integration_test_php_client_set'), | ||
]) | ||
->send(); | ||
|
||
$this->assertSame(6, $response->getNumberOfCommands()); | ||
$this->assertSame(6, $response->getNumberOfSuccessfulCommands()); | ||
$this->assertSame(0, $response->getNumberOfFailedCommands()); | ||
$this->assertSame(0, $response->getNumberOfSkippedCommands()); | ||
} | ||
} |