-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add namespaces
- Loading branch information
alexwanyoike
committed
Nov 15, 2017
1 parent
6aaaffd
commit 92b2d46
Showing
23 changed files
with
717 additions
and
9 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
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,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))); | ||
} | ||
} |
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
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,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))); | ||
} | ||
|
||
} |
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,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))); | ||
} | ||
} |
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
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,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; | ||
} | ||
|
||
} |
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,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()); | ||
} | ||
} |
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,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()); | ||
} | ||
} |
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,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()); | ||
} | ||
} |
Oops, something went wrong.