Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
Add namespaces
  • Loading branch information
alexwanyoike committed Nov 15, 2017
1 parent 6aaaffd commit 92b2d46
Show file tree
Hide file tree
Showing 23 changed files with 717 additions and 9 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
"psr-4": {
"SnowIO\\FredhopperDataModel\\": "src"
}
},
"autoload-dev": {
"files": ["src/Internal/functions.php"],
"psr-4": {
"SnowIO\\FredhopperDataModel\\Test\\": "test/unit"
}
}
}
81 changes: 81 additions & 0 deletions test/unit/AttributeDataSetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
declare(strict_types = 1);
namespace SnowIO\FredhopperDataModel\Test;

use PHPUnit\Framework\TestCase;
use SnowIO\FredhopperDataModel\AttributeData;
use SnowIO\FredhopperDataModel\AttributeDataSet;
use SnowIO\FredhopperDataModel\AttributeType;
use SnowIO\FredhopperDataModel\Command\DeleteAttributeCommand;
use SnowIO\FredhopperDataModel\Command\SaveAttributeCommand;
use SnowIO\FredhopperDataModel\InternationalizedString;
use SnowIO\FredhopperDataModel\LocalizedString;

class AttributeDataSetTest extends TestCase
{
use CommandHelper;

public function testWithers()
{
$attributeDataSet = AttributeDataSet::of([
AttributeData::of('volume', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Volume', 'en_GB'))),
AttributeData::of('density', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Density', 'en_GB'))),
AttributeData::of('length', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Length', 'en_GB'))),
AttributeData::of('width', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Width', 'en_GB'))),
]);

$attributeDataSet = $attributeDataSet->with(AttributeData::of('volume', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Volume', 'en_GB'))));

self::assertTrue($attributeDataSet->equals(AttributeDataSet::of([
AttributeData::of('volume', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Volume', 'en_GB'))),
AttributeData::of('density', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Density', 'en_GB'))),
AttributeData::of('length', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Length', 'en_GB'))),
AttributeData::of('width', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Width', 'en_GB'))),
])));
}

public function testMapToSaveCommands()
{
$attributeDataSet = AttributeDataSet::of([
AttributeData::of('volume', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Volume', 'en_GB'))),
AttributeData::of('density', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Density', 'en_GB'))),
]);

$expectedCommands = [
'volume' => SaveAttributeCommand::of(AttributeData::of('volume', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Volume', 'en_GB'))))->withTimestamp(1),
'density' => SaveAttributeCommand::of(AttributeData::of('density', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Density', 'en_GB'))))->withTimestamp(1),
];

self::assertEquals($this->getJson($expectedCommands), $this->getJson($attributeDataSet->mapToSaveCommands(1)));
}

public function testMapToDeleteCommands()
{
$attributeDataSet = AttributeDataSet::of([
AttributeData::of('volume', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Volume', 'en_GB'))),
AttributeData::of('density', AttributeType::FLOAT, InternationalizedString::create()
->with(LocalizedString::of('Density', 'en_GB'))),
]);

$expectedCommands = [
'volume' => DeleteAttributeCommand::of('volume')->withTimestamp(1),
'density' => DeleteAttributeCommand::of('density')->withTimestamp(1),
];

self::assertEquals($this->getJson($expectedCommands), $this->getJson($attributeDataSet->mapToDeleteCommands(1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SnowIO\FredhopperDataModel\AttributeData;
use SnowIO\FredhopperDataModel\InternationalizedString;

class AttributeTest extends \PHPUnit\Framework\TestCase
class AttributeDataTest extends \PHPUnit\Framework\TestCase
{

public function testObjectInitialisation()
Expand Down
72 changes: 72 additions & 0 deletions test/unit/AttributeOptionSetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
declare(strict_types = 1);
namespace SnowIO\FredhopperDataModel\Test;

use PHPUnit\Framework\TestCase;
use SnowIO\FredhopperDataModel\AttributeOption;
use SnowIO\FredhopperDataModel\AttributeOptionSet;
use SnowIO\FredhopperDataModel\Command\DeleteAttributeOptionCommand;
use SnowIO\FredhopperDataModel\Command\SaveAttributeOptionCommand;

class AttributeOptionSetTest extends TestCase
{
use CommandHelper;

public function testWithers()
{
$attributeOptionSet = AttributeOptionSet::of([
AttributeOption::of('size', 'large'),
AttributeOption::of('color', 'blue'),
AttributeOption::of('material', 'mahogany')
]);

$attributeOptionSet = $attributeOptionSet->with(AttributeOption::of('terrain', 'woodland'));
self::assertTrue($attributeOptionSet->equals(AttributeOptionSet::of([
AttributeOption::of('size', 'large'),
AttributeOption::of('color', 'blue'),
AttributeOption::of('material', 'mahogany'),
AttributeOption::of('terrain', 'woodland')
])));

$attributeOptionSet = $attributeOptionSet->with(AttributeOption::of('terrain', 'tundra'));
self::assertTrue($attributeOptionSet->equals(AttributeOptionSet::of([
AttributeOption::of('size', 'large'),
AttributeOption::of('color', 'blue'),
AttributeOption::of('material', 'mahogany'),
AttributeOption::of('terrain', 'woodland'),
AttributeOption::of('terrain', 'tundra')
])));
}

public function testMapToSaveCommand()
{
$attributeOptionSet = AttributeOptionSet::of([
AttributeOption::of('size', 'large'),
AttributeOption::of('color', 'blue'),
]);

$expectedCommands = [
'size-large' => SaveAttributeOptionCommand::of(AttributeOption::of('size', 'large'))->withTimestamp(1),
'color-blue' => SaveAttributeOptionCommand::of(AttributeOption::of('color', 'blue'))->withTimestamp(1),
];

self::assertEquals($this->getJson($expectedCommands),
$this->getJson($attributeOptionSet->mapToSaveCommands(1)));
}

public function testMapToDeleteCommand()
{
$attributeOptionSet = AttributeOptionSet::of([
AttributeOption::of('size', 'large'),
AttributeOption::of('color', 'blue'),
]);

$expectedCommands = [
'size-large' => DeleteAttributeOptionCommand::of('size','large')->withTimestamp(1),
'color-blue' => DeleteAttributeOptionCommand::of('color','blue')->withTimestamp(1),
];

self::assertEquals($this->getJson($expectedCommands), $this->getJson($attributeOptionSet->mapToDeleteCommands(1)));
}

}
96 changes: 96 additions & 0 deletions test/unit/CategoryDataSetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
declare(strict_types = 1);
namespace SnowIO\FredhopperDataModel\Test;

use PHPUnit\Framework\TestCase;
use SnowIO\FredhopperDataModel\CategoryData;
use SnowIO\FredhopperDataModel\CategoryDataSet;
use SnowIO\FredhopperDataModel\Command\DeleteCategoryCommand;
use SnowIO\FredhopperDataModel\Command\SaveCategoryCommand;
use SnowIO\FredhopperDataModel\InternationalizedString;
use SnowIO\FredhopperDataModel\LocalizedString;

class CategoryDataSetTest extends TestCase
{
use CommandHelper;

public function testWithers()
{
$categoryDataSet = CategoryDataSet::of([
CategoryData::of('mensshoes', InternationalizedString::of([
LocalizedString::of('Men\'s Shoes', 'en_GB'),
])),
CategoryData::of('mensshirts', InternationalizedString::of([
LocalizedString::of('Men\'s Shirts', 'en_GB'),
])),
CategoryData::of('mensunderware', InternationalizedString::of([
LocalizedString::of('Men\'s Underware', 'en_GB'),
])),
]);

$categoryDataSet = $categoryDataSet->with(CategoryData::of('menswatches',
InternationalizedString::of([LocalizedString::of('Men\'s Watches', 'en_GB')])));
self::assertTrue($categoryDataSet->equals(CategoryDataSet::of([
CategoryData::of('mensshoes', InternationalizedString::of([
LocalizedString::of('Men\'s Shoes', 'en_GB'),
])),
CategoryData::of('mensshirts', InternationalizedString::of([
LocalizedString::of('Men\'s Shirts', 'en_GB'),
])),
CategoryData::of('mensunderware', InternationalizedString::of([
LocalizedString::of('Men\'s Underware', 'en_GB'),
])),
CategoryData::of('menswatches',
InternationalizedString::of([LocalizedString::of('Men\'s Watches', 'en_GB')])),
])));

$categoryDataSet = $categoryDataSet->with(CategoryData::of('mensunderware',
InternationalizedString::of([LocalizedString::of('Men\'s Briefs', 'en_GB')])));
self::assertTrue($categoryDataSet->equals(CategoryDataSet::of([
CategoryData::of('mensshoes', InternationalizedString::of([
LocalizedString::of('Men\'s Shoes', 'en_GB'),
])),
CategoryData::of('mensshirts', InternationalizedString::of([
LocalizedString::of('Men\'s Shirts', 'en_GB'),
])),
CategoryData::of('mensunderware', InternationalizedString::of([
LocalizedString::of('Men\'s Briefs', 'en_GB'),
])),
CategoryData::of('menswatches',
InternationalizedString::of([LocalizedString::of('Men\'s Watches', 'en_GB')])),
])));
}

public function testMapToSaveCommand()
{
$categoryDataSet = CategoryDataSet::of([
CategoryData::of('mensshoes', InternationalizedString::of([LocalizedString::of('Men\'s Shoes', 'en_GB')])),
CategoryData::of('mensshirts',
InternationalizedString::of([LocalizedString::of('Men\'s Shirts', 'en_GB')])),
]);

$expectedSet = [
'mensshoes' => SaveCategoryCommand::of(CategoryData::of('mensshoes',
InternationalizedString::of([LocalizedString::of('Men\'s Shoes', 'en_GB')])))->withTimestamp(1),
'mensshirts' => SaveCategoryCommand::of(CategoryData::of('mensshirts',
InternationalizedString::of([LocalizedString::of('Men\'s Shirts', 'en_GB')])))->withTimestamp(1),
];

self::assertEquals($this->getJson($expectedSet), $this->getJson($categoryDataSet->mapToSaveCommands(1)));
}

public function testMapToDeleteCommand()
{
$categoryDataSet = CategoryDataSet::of([
CategoryData::of('mensshoes', InternationalizedString::of([LocalizedString::of('Men\'s Shoes', 'en_GB')])),
CategoryData::of('mensshirts', InternationalizedString::of([LocalizedString::of('Men\'s Shirts', 'en_GB')])),
]);

$expectedSet = [
'mensshoes' => DeleteCategoryCommand::of('mensshoes')->withTimestamp(1),
'mensshirts' => DeleteCategoryCommand::of('mensshirts')->withTimestamp(1),
];

self::assertEquals($this->getJson($expectedSet), $this->getJson($categoryDataSet->mapToDeleteCommands(1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SnowIO\FredhopperDataModel\CategoryData;
use SnowIO\FredhopperDataModel\InternationalizedString;

class CategoryTest extends \PHPUnit\Framework\TestCase
class CategoryDataTest extends \PHPUnit\Framework\TestCase
{

public function testObjectInitialisation()
Expand Down
28 changes: 28 additions & 0 deletions test/unit/Command/CommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types = 1);
namespace SnowIO\FredhopperDataModel\Test;

use PHPUnit\Framework\TestCase;
use SnowIO\FredhopperDataModel\Command\Command;

class CommandTest extends TestCase
{
public function testToJson()
{
/** @var Command $command */
$command = $this->createCommand()->withTimestamp(1509530316);
self::assertEquals([
'@timestamp' => 1509530316,
], $command->toJson());

$command = $this->createCommand();
self::assertEquals([], $command->toJson());
}

public function createCommand()
{
$commandClass = new class extends Command {};
return new $commandClass;
}

}
24 changes: 24 additions & 0 deletions test/unit/Command/DeleteAttributeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types = 1);
namespace SnowIO\FredhopperDataModel\Test;
use PHPUnit\Framework\TestCase;
use SnowIO\FredhopperDataModel\Command\DeleteAttributeCommand;

class DeleteAttributeCommandTest extends TestCase
{
public function testToJson()
{
$command = DeleteAttributeCommand::of('volume')->withTimestamp(1510744232);

self::assertEquals([
'@timestamp' => 1510744232,
'attribute_id' => 'volume',
], $command->toJson());
}

public function testAccessor()
{
$command = DeleteAttributeCommand::of('volume');
self::assertEquals('volume', $command->getAttributeId());
}
}
24 changes: 24 additions & 0 deletions test/unit/Command/DeleteAttributeOptionCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use SnowIO\FredhopperDataModel\Command\DeleteAttributeOptionCommand;

class DeleteAttributeOptionCommandTest extends TestCase
{
public function testToJson()
{
$command = DeleteAttributeOptionCommand::of('size', 'large')->withTimestamp(1510744232);
self::assertEquals([
'@timestamp' => 1510744232,
'attribute_id' => 'size',
'value_id' => 'large',
], $command->toJson());
}

public function testAccessor()
{
$command = DeleteAttributeOptionCommand::of('size', 'large');
self::assertEquals('size', $command->getAttributeId());
self::assertEquals('large', $command->getValueId());
}
}
24 changes: 24 additions & 0 deletions test/unit/Command/DeleteCategoryCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types = 1);
namespace SnowIO\FredhopperDataModel\Test;

use PHPUnit\Framework\TestCase;
use SnowIO\FredhopperDataModel\Command\DeleteCategoryCommand;

class DeleteCategoryCommandTest extends TestCase
{
public function testToJson()
{
$command = DeleteCategoryCommand::of('mensshoes')->withTimestamp(1510744232);
self::assertEquals([
'@timestamp' => 1510744232,
'category_id' => 'mensshoes',
], $command->toJson());
}

public function testAccessors()
{
$command = DeleteCategoryCommand::of('mensshoes');
self::assertEquals('mensshoes', $command->getCategoryId());
}
}
Loading

0 comments on commit 92b2d46

Please sign in to comment.