Skip to content

Commit

Permalink
Add Item Properties setup integration test case
Browse files Browse the repository at this point in the history
  • Loading branch information
foglcz authored and OndraM committed Nov 27, 2017
1 parent 6a7a4ce commit fe4aa47
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/IntegrationTests/IntegrationTestCase.php
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;
}
}
122 changes: 122 additions & 0 deletions tests/IntegrationTests/ItemPropertiesSetupTest.php
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());
}
}

0 comments on commit fe4aa47

Please sign in to comment.