From 5c2e3d0adae467917887656e408ee672daa40b61 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sat, 22 Mar 2014 12:41:20 +0100 Subject: [PATCH 01/17] Add phpspec dependency --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 6a68a12..3459867 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,9 @@ "php": ">=5.3.3", "symfony/symfony": ">=2.1.0" }, + "require-dev": { + "phpspec/phpspec": "dev-develop@dev" + }, "autoload": { "psr-0": { "Akeneo\\Bundle\\MeasureBundle": "" } }, From 36df5c63dcc693fedb335f5da297844a8029b822 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sat, 22 Mar 2014 12:49:37 +0100 Subject: [PATCH 02/17] Change phpspec version used --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3459867..23a8131 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,10 @@ "symfony/symfony": ">=2.1.0" }, "require-dev": { - "phpspec/phpspec": "dev-develop@dev" + "phpspec/phpspec": "2.0.*@dev" + }, + "config": { + "bin-dir": "bin" }, "autoload": { "psr-0": { "Akeneo\\Bundle\\MeasureBundle": "" } From f17f45a30564f5e41e9622782617c63f765ed16f Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sat, 22 Mar 2014 12:50:05 +0100 Subject: [PATCH 03/17] Add phpspec binary --- bin/phpspec | 1 + 1 file changed, 1 insertion(+) create mode 120000 bin/phpspec diff --git a/bin/phpspec b/bin/phpspec new file mode 120000 index 0000000..22e0618 --- /dev/null +++ b/bin/phpspec @@ -0,0 +1 @@ +../vendor/phpspec/phpspec/bin/phpspec \ No newline at end of file From 39c214412b816974ad321afe7503c631eb70bab3 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sat, 22 Mar 2014 13:32:45 +0100 Subject: [PATCH 04/17] Add Configuration spec --- .../DependencyInjection/ConfigurationSpec.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 spec/Akeneo/Bundle/MeasureBundle/DependencyInjection/ConfigurationSpec.php diff --git a/spec/Akeneo/Bundle/MeasureBundle/DependencyInjection/ConfigurationSpec.php b/spec/Akeneo/Bundle/MeasureBundle/DependencyInjection/ConfigurationSpec.php new file mode 100644 index 0000000..e5f3997 --- /dev/null +++ b/spec/Akeneo/Bundle/MeasureBundle/DependencyInjection/ConfigurationSpec.php @@ -0,0 +1,13 @@ +getConfigTreeBuilder()->shouldBeAnInstanceOf('Symfony\Component\Config\Definition\Builder\TreeBuilder'); + } +} From 3b70665cc190141edb0a0b29ff386bf7514a0879 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 23 Mar 2014 21:32:25 +0100 Subject: [PATCH 05/17] Add spec for measure converter --- .../Convert/MeasureConverterSpec.php | 31 +++++++++++++++++++ .../Resources/config/measure-test.yml | 10 ++++++ 2 files changed, 41 insertions(+) create mode 100644 spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php create mode 100644 spec/Akeneo/Bundle/MeasureBundle/Resources/config/measure-test.yml diff --git a/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php b/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php new file mode 100644 index 0000000..d2a082b --- /dev/null +++ b/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php @@ -0,0 +1,31 @@ +beConstructedWith($config); + } + + function it_should_allow_to_define_the_family() + { + $this->setFamily('Length')->shouldReturnInstanceOf('Akeneo\Bundle\MeasureBundle\Convert\MeasureConverter'); + } + + function it_should_throw_an_exception_if_an_unknown_family_is_set() + { + + } +} diff --git a/spec/Akeneo/Bundle/MeasureBundle/Resources/config/measure-test.yml b/spec/Akeneo/Bundle/MeasureBundle/Resources/config/measure-test.yml new file mode 100644 index 0000000..5fc4bde --- /dev/null +++ b/spec/Akeneo/Bundle/MeasureBundle/Resources/config/measure-test.yml @@ -0,0 +1,10 @@ +measures_config: + Length: + standard: METER + units: + CENTIMETER: + convert: [{'div': 0.01}] + format: cm + METER: + convert: [{'test': 1}] + format: m From 9c4ec075b780be5053e6d47eb7039ce19f466a52 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 10 Aug 2014 13:27:26 +0200 Subject: [PATCH 06/17] Integrate travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7d42f01..f7066f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,5 @@ before_script: - composer self-update - composer update -script: phpunit --coverage-text +script: /bin/phpspec run spec/ From f6175e03f7c75925d24edb346f16bde16a7e4675 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 10 Aug 2014 13:33:32 +0200 Subject: [PATCH 07/17] Fix typo to integrate travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f7066f4..c141020 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,5 @@ before_script: - composer self-update - composer update -script: /bin/phpspec run spec/ +script: ./bin/phpspec run spec/ From 662c7c8994795ab3b6de5665777db083990ec812 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 10 Aug 2014 15:08:41 +0200 Subject: [PATCH 08/17] Remove IDE files from gitignore --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index af6052f..082d69c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -/.settings -/.buildpath -/.project /cov /vendor /composer.phar From 984199cc173b400f6c4f1bc9078a729b7387c068 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 10 Aug 2014 15:09:18 +0200 Subject: [PATCH 09/17] Add specs for measure converter --- .../Convert/MeasureConverterSpec.php | 62 ++++++++++++++++++- .../Resources/config/measure-test.yml | 12 ++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php b/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php index d2a082b..366d147 100644 --- a/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php +++ b/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php @@ -2,7 +2,11 @@ namespace spec\Akeneo\Bundle\MeasureBundle\Convert; +use Akeneo\Bundle\MeasureBundle\Exception\UnknownFamilyMeasureException; +use Akeneo\Bundle\MeasureBundle\Exception\UnknownMeasureException; +use Akeneo\Bundle\MeasureBundle\Family\WeightFamilyInterface; use PhpSpec\ObjectBehavior; +use Prophecy\Argument; use Symfony\Component\Yaml\Yaml; class MeasureConverterSpec extends ObjectBehavior @@ -19,13 +23,65 @@ function let() $this->beConstructedWith($config); } - function it_should_allow_to_define_the_family() + function it_allows_to_define_the_family() { - $this->setFamily('Length')->shouldReturnInstanceOf('Akeneo\Bundle\MeasureBundle\Convert\MeasureConverter'); + $this->setFamily('Length')->shouldReturnAnInstanceOf('Akeneo\Bundle\MeasureBundle\Convert\MeasureConverter'); } - function it_should_throw_an_exception_if_an_unknown_family_is_set() + function it_throws_an_exception_if_an_unknown_family_is_set() { + $this + ->shouldThrow( + new UnknownFamilyMeasureException() + ) + ->during('setFamily', ['foo']); + } + + function it_converts_a_value_from_a_base_unit_to_a_final_unit() + { + $this->setFamily('Weight'); + $this->convert( + WeightFamilyInterface::KILOGRAM, + WeightFamilyInterface::MILLIGRAM, + 1 + )->shouldReturn((double) 1000000); + } + + function it_converts_a_value_to_a_standard_unit() + { + $this->setFamily('Weight'); + $this->convertBaseToStandard( + WeightFamilyInterface::MILLIGRAM, + 1000 + )->shouldReturn((double) 1); + } + + function it_converts_a_standard_value_to_a_final_unit() + { + $this->setFamily('Weight'); + $this->convertStandardToResult( + WeightFamilyInterface::KILOGRAM, + 10 + )->shouldReturn((double) 0.01); + } + + function it_throws_an_exception_if_the_unit_measure_does_not_exist() + { + $this->setFamily('Weight'); + $this + ->shouldThrow( + new UnknownMeasureException( + 'Could not find metric unit "foo" in family "Weight"' + ) + ) + ->during('convertBaseToStandard', ['foo', Argument::any()]); + $this + ->shouldThrow( + new UnknownMeasureException( + 'Could not find metric unit "foo" in family "Weight"' + ) + ) + ->during('convertStandardToResult', ['foo', Argument::any()]); } } diff --git a/spec/Akeneo/Bundle/MeasureBundle/Resources/config/measure-test.yml b/spec/Akeneo/Bundle/MeasureBundle/Resources/config/measure-test.yml index 5fc4bde..ff09d80 100644 --- a/spec/Akeneo/Bundle/MeasureBundle/Resources/config/measure-test.yml +++ b/spec/Akeneo/Bundle/MeasureBundle/Resources/config/measure-test.yml @@ -8,3 +8,15 @@ measures_config: METER: convert: [{'test': 1}] format: m + Weight: + standard: GRAM + units: + MILLIGRAM: + convert: [{'mul': 0.001}] + symbol: mg + GRAM: + convert: [{'mul': 1}] + symbol: g + KILOGRAM: + convert: [{'mul': 1000}] + symbol: kg From 781d02f5bed0de7ca6e1b2b2294fc7d59aec08fd Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 10 Aug 2014 15:17:41 +0200 Subject: [PATCH 10/17] Make it compatible with PHP 5.3 --- .../Bundle/MeasureBundle/Convert/MeasureConverterSpec.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php b/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php index 366d147..9716b93 100644 --- a/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php +++ b/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php @@ -34,7 +34,7 @@ function it_throws_an_exception_if_an_unknown_family_is_set() ->shouldThrow( new UnknownFamilyMeasureException() ) - ->during('setFamily', ['foo']); + ->during('setFamily', array('foo')); } function it_converts_a_value_from_a_base_unit_to_a_final_unit() @@ -74,7 +74,7 @@ function it_throws_an_exception_if_the_unit_measure_does_not_exist() 'Could not find metric unit "foo" in family "Weight"' ) ) - ->during('convertBaseToStandard', ['foo', Argument::any()]); + ->during('convertBaseToStandard', array('foo', Argument::any())); $this ->shouldThrow( @@ -82,6 +82,6 @@ function it_throws_an_exception_if_the_unit_measure_does_not_exist() 'Could not find metric unit "foo" in family "Weight"' ) ) - ->during('convertStandardToResult', ['foo', Argument::any()]); + ->during('convertStandardToResult', array('foo', Argument::any())); } } From 9e1ce8ed25daa0fba6a83c274ea424697e694eff Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 10 Aug 2014 15:23:39 +0200 Subject: [PATCH 11/17] Define classes as parameters --- Resources/config/services.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 29c3ca4..d36999d 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,10 +1,12 @@ parameters: + akeneo_measure.convert.measure_converter.class: Akeneo\Bundle\MeasureBundle\Convert\MeasureConverter + akeneo_measure.manager.measure_manager.class: Akeneo\Bundle\MeasureBundle\Manager\MeasureManager akeneo_measure.measures_config: ~ services: akeneo_measure.measure_converter: - class: Akeneo\Bundle\MeasureBundle\Convert\MeasureConverter + class: %akeneo_measure.convert.measure_converter.class% arguments: [%akeneo_measure.measures_config%] akeneo_measure.manager: - class: Akeneo\Bundle\MeasureBundle\Manager\MeasureManager + class: %akeneo_measure.manager.measure_manager.class% From d44d51575dd779a071ee4fd29aad1f14859e6c0a Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 10 Aug 2014 16:58:14 +0200 Subject: [PATCH 12/17] Add spec for measure manager --- .../Manager/MeasureManagerSpec.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 spec/Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php diff --git a/spec/Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php b/spec/Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php new file mode 100644 index 0000000..4cc325c --- /dev/null +++ b/spec/Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php @@ -0,0 +1,57 @@ + + * @copyright 2014 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class MeasureManagerSpec extends ObjectBehavior +{ + function let() + { + $filename = realpath(dirname(__FILE__) .'/../Resources/config/measure-test.yml'); + if (!file_exists($filename)) { + throw new \Exception(sprintf('Config file "%s" does not exist', $filename)); + } + + $config = Yaml::parse($filename); + + $this->setMeasureConfig($config['measures_config']); + } + + function it_throws_an_exception_when_try_to_get_symbols_of_unknown_family() + { + $this + ->shouldThrow( + new \InvalidArgumentException('Undefined measure family "foo"') + ) + ->during('getUnitSymbolsForFamily', array('foo')); + } + + function it_returns_unit_symbols_list_from_a_family() + { + $this + ->getUnitSymbolsForFamily(WeightFamilyInterface::FAMILY) + ->shouldReturn( + array( + 'MILLIGRAM' => 'mg', + 'GRAM' => 'g', + 'KILOGRAM' => 'kg' + ) + ); + } + + function it_returns_standard_unit_for_a_family() + { + $this + ->getStandardUnitForFamily(WeightFamilyInterface::FAMILY) + ->shouldReturn(WeightFamilyInterface::GRAM); + } +} From 41ad304a5bd72f4223bb4d86526d9b4757961321 Mon Sep 17 00:00:00 2001 From: Romain Monceau Date: Sun, 10 Aug 2014 17:01:26 +0200 Subject: [PATCH 13/17] Remove Unit Tests --- Tests/Unit/Convert/MeasureConverterTest.php | 326 ------------------ .../DependencyInjection/ConfigurationTest.php | 22 -- Tests/Unit/Files/measure-test.yml | 10 - Tests/Unit/Manager/MeasureManagerTest.php | 68 ---- Tests/bootstrap.php | 2 - 5 files changed, 428 deletions(-) delete mode 100644 Tests/Unit/Convert/MeasureConverterTest.php delete mode 100644 Tests/Unit/DependencyInjection/ConfigurationTest.php delete mode 100644 Tests/Unit/Files/measure-test.yml delete mode 100644 Tests/Unit/Manager/MeasureManagerTest.php delete mode 100644 Tests/bootstrap.php diff --git a/Tests/Unit/Convert/MeasureConverterTest.php b/Tests/Unit/Convert/MeasureConverterTest.php deleted file mode 100644 index 37bf332..0000000 --- a/Tests/Unit/Convert/MeasureConverterTest.php +++ /dev/null @@ -1,326 +0,0 @@ -initializeConfig($configFile); - - $this->converter = $this->initializeConverter($config); - } - - /** - * Initialize a configuration - * @param string $filepath - * - * @throws \Exception - * - * @return array - */ - protected function initializeConfig($filepath) - { - if (!file_exists($filepath)) { - throw new \Exception("Config file $filepath not exists"); - } - - return Yaml::parse(file_get_contents($filepath)); - } - - /** - * Initialize converter - * @param array $config - * - * @throws \Exception - * - * @return \Akeneo\Bundle\MeasureBundle\Convert\MeasureConverter - */ - protected function initializeConverter($config) - { - return new MeasureConverter($config); - } - - /** - * Test converter with data in provider method - * @param string $family MeasureFamily for conversion - * @param string $baseUnit Base unit used by base value - * @param string $convertedUnit Converted unit asked - * @param number $baseValue Base value - * @param number $expectedValue Expected value after conversion - * - * @dataProvider provider - */ - public function testConvert($family, $baseUnit, $convertedUnit, $baseValue, $expectedValue) - { - $this->converter->setFamily($family); - - $convertedValue = $this->converter->convert($baseUnit, $convertedUnit, $baseValue); - $this->assertEquals($expectedValue, $convertedValue); - - $resultValue = $this->converter->convert($convertedUnit, $baseUnit, $convertedValue); - $this->assertEquals($baseValue, $resultValue); - } - - /** - * Data provider - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - * - * @return array - * - * @static - */ - public static function provider() - { - return array( - // Area tests - array( - AreaFamilyInterface::FAMILY, AreaFamilyInterface::SQUARE_METER, AreaFamilyInterface::HECTARE, 200, 0.02 - ), - array( - AreaFamilyInterface::FAMILY, - AreaFamilyInterface::SQUARE_INCH, - AreaFamilyInterface::SQUARE_MIL, - 10, - 10000000 - ), - array( - AreaFamilyInterface::FAMILY, - AreaFamilyInterface::SQUARE_FURLONG, - AreaFamilyInterface::SQUARE_MILE, - 100, - 1.5625062462063 - ), - // Binary tests - array( - BinaryFamilyInterface::FAMILY, BinaryFamilyInterface::BYTE, BinaryFamilyInterface::KILOBYTE, 1024, 1 - ), - array( - BinaryFamilyInterface::FAMILY, - BinaryFamilyInterface::GIGABYTE, - BinaryFamilyInterface::BIT, - 2, - 17179869184 - ), - // Frequency tests - array( - FrequencyFamilyInterface::FAMILY, - FrequencyFamilyInterface::HERTZ, - FrequencyFamilyInterface::KILOHERTZ, - 10000, - 10 - ), - array( - FrequencyFamilyInterface::FAMILY, - FrequencyFamilyInterface::TERAHERTZ, - FrequencyFamilyInterface::MEGAHERTZ, - 2, - 2000000 - ), - // Length tests - array( - LengthFamilyInterface::FAMILY, - LengthFamilyInterface::MILLIMETER, - LengthFamilyInterface::CENTIMETER, - 50, - 5 - ), - array( - LengthFamilyInterface::FAMILY, - LengthFamilyInterface::INCH, - LengthFamilyInterface::MILE, - 15000, - 0.23674242424242 - ), - array( - LengthFamilyInterface::FAMILY, - LengthFamilyInterface::KILOMETER, - LengthFamilyInterface::YARD, - 10, - 10936.132983377 - ), - // Power tests - array( - PowerFamilyInterface::FAMILY, PowerFamilyInterface::WATT, PowerFamilyInterface::KILOWATT, 10000, 10 - ), - array( - PowerFamilyInterface::FAMILY, PowerFamilyInterface::TERAWATT, PowerFamilyInterface::MEGAWATT, 2, 2000000 - ), - array( - PowerFamilyInterface::FAMILY, PowerFamilyInterface::GIGAWATT, PowerFamilyInterface::TERAWATT, 5, 0.005 - ), - // Speed tests - array( - SpeedFamilyInterface::FAMILY, - SpeedFamilyInterface::KILOMETER_PER_HOUR, - SpeedFamilyInterface::METER_PER_SECOND, - 36, - 10 - ), - array( - SpeedFamilyInterface::FAMILY, - SpeedFamilyInterface::FOOT_PER_SECOND, - SpeedFamilyInterface::MILE_PER_HOUR, - 17, - 11.590909090909 - ), - array( - SpeedFamilyInterface::FAMILY, - SpeedFamilyInterface::YARD_PER_HOUR, - SpeedFamilyInterface::METER_PER_MINUTE, - 26, - 0.39624 - ), - // Temperature tests - array( - TemperatureFamilyInterface::FAMILY, - TemperatureFamilyInterface::CELSIUS, - TemperatureFamilyInterface::FAHRENHEIT, - 20, - 68 - ), - array( - TemperatureFamilyInterface::FAMILY, - TemperatureFamilyInterface::REAUMUR, - TemperatureFamilyInterface::RANKINE, - 6, - 505.17 - ), - array( - TemperatureFamilyInterface::FAMILY, - TemperatureFamilyInterface::FAHRENHEIT, - TemperatureFamilyInterface::REAUMUR, - 26720.33, - 11861.48 - ), - // Volume tests - array( - VolumeFamilyInterface::FAMILY, VolumeFamilyInterface::CUBIC_METER, VolumeFamilyInterface::LITER, 5, 5000 - ), - array( - VolumeFamilyInterface::FAMILY, - VolumeFamilyInterface::MILLILITER, - VolumeFamilyInterface::PINT, - 568.26125, - 1 - ), - array( - VolumeFamilyInterface::FAMILY, - VolumeFamilyInterface::CUBIC_INCH, - VolumeFamilyInterface::OUNCE, - 12, - 6.9209283170784 - ), - // Weight tests - array( - WeightFamilyInterface::FAMILY, - WeightFamilyInterface::GRAM, - WeightFamilyInterface::OUNCE, - 3059, - 107.90304960377 - ), - array( - WeightFamilyInterface::FAMILY, - WeightFamilyInterface::POUND, - WeightFamilyInterface::KILOGRAM, - 2, - 0.90718474 - ), - array( - WeightFamilyInterface::FAMILY, - WeightFamilyInterface::GRAIN, - WeightFamilyInterface::MARC, - 500, - 0.13237775280899 - ), - ); - } - - /** - * Test related exception - * @expectedException Akeneo\Bundle\MeasureBundle\Exception\UnknownFamilyMeasureException - */ - public function testUnknownFamilyMeasureException() - { - $this->converter->setFamily('test-family'); - } - - /** - * Test related exception in base to standard method - * @expectedException Akeneo\Bundle\MeasureBundle\Exception\UnknownMeasureException - */ - public function testUnknownMeasureExceptionBaseToStandard() - { - $this->converter->setFamily(WeightFamilyInterface::FAMILY); - $this->converter->convert('test-unit', WeightFamilyInterface::GRAM, 50); - } - - /** - * Test related exception in standard to final method - * @expectedException Akeneo\Bundle\MeasureBundle\Exception\UnknownMeasureException - */ - public function testUnknownMeasureExceptionStandardToFinal() - { - $this->converter->setFamily(WeightFamilyInterface::FAMILY); - $this->converter->convert(WeightFamilyInterface::GRAM, 'test-unit', 50); - } - - /** - * Test related exception in base to standard method - * @expectedException Akeneo\Bundle\MeasureBundle\Exception\UnknownOperatorException - */ - public function testUnknownOperatorExceptionBaseToStandard() - { - $configFile = dirname(__FILE__) .'/../Files/measure-test.yml'; - $config = $this->initializeConfig($configFile); - - $converter = $this->initializeConverter($config); - $converter->setFamily(LengthFamilyInterface::FAMILY); - $converter->convert(LengthFamilyInterface::METER, LengthFamilyInterface::CENTIMETER, 100); - } - - /** - * Test related exception in standard to final method - * @expectedException Akeneo\Bundle\MeasureBundle\Exception\UnknownOperatorException - */ - public function testUnknownOperatorExceptionStandardToFinal() - { - $configFile = dirname(__FILE__) .'/../Files/measure-test.yml'; - $config = $this->initializeConfig($configFile); - - $converter = $this->initializeConverter($config); - $converter->setFamily(LengthFamilyInterface::FAMILY); - $converter->convert(LengthFamilyInterface::CENTIMETER, LengthFamilyInterface::METER, 100); - } -} diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index 835ae35..0000000 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,22 +0,0 @@ -assertTrue($configuration->getConfigTreeBuilder() instanceof TreeBuilder); - } -} diff --git a/Tests/Unit/Files/measure-test.yml b/Tests/Unit/Files/measure-test.yml deleted file mode 100644 index 5fc4bde..0000000 --- a/Tests/Unit/Files/measure-test.yml +++ /dev/null @@ -1,10 +0,0 @@ -measures_config: - Length: - standard: METER - units: - CENTIMETER: - convert: [{'div': 0.01}] - format: cm - METER: - convert: [{'test': 1}] - format: m diff --git a/Tests/Unit/Manager/MeasureManagerTest.php b/Tests/Unit/Manager/MeasureManagerTest.php deleted file mode 100644 index 170b4ce..0000000 --- a/Tests/Unit/Manager/MeasureManagerTest.php +++ /dev/null @@ -1,68 +0,0 @@ -measureManager = new MeasureManager; - $this->measureManager->setMeasureConfig( - array( - 'WEIGHT' => array( - 'standard' => 'KILOGRAM', - 'units' => array( - 'KILOGRAM' => array('symbol' => 'kg'), - 'GRAM' => array('symbol' => 'g') - ) - ) - ) - ); - } - - public function testGetUnitForFamily() - { - $this->assertEquals( - array( - 'KILOGRAM' => 'kg', - 'GRAM' => 'g', - ), - $this->measureManager->getUnitSymbolsForFamily('WEIGHT') - ); - } - - public function testInvalidFamilyWhenGettingUnitForFamily() - { - try { - $this->measureManager->getUnitSymbolsForFamily('LENGTH'); - } catch (\InvalidArgumentException $e) { - $this->assertEquals('Undefined measure family "LENGTH"', $e->getMessage()); - - return; - } - - $this->fail('An InvalidArgumentException has not been raised.'); - } - - public function testGetStandardUnitForFamily() - { - $this->assertEquals( - 'KILOGRAM', - $this->measureManager->getStandardUnitForFamily('WEIGHT') - ); - } - - public function testUnitExistsInFamily() - { - $this->assertEquals( - true, - $this->measureManager->unitExistsInFamily('kg', 'WEIGHT') - ); - $this->assertEquals( - false, - $this->measureManager->unitExistsInFamily('KG', 'WEIGHT') - ); - } -} diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php deleted file mode 100644 index 51bede3..0000000 --- a/Tests/bootstrap.php +++ /dev/null @@ -1,2 +0,0 @@ - Date: Sun, 10 Aug 2014 18:01:58 +0200 Subject: [PATCH 14/17] Remove phpunit.xml.dist file --- phpunit.xml.dist | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 phpunit.xml.dist diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 731ed33..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - ./Tests - - - - - - . - - ./vendor - ./Tests - - - - - \ No newline at end of file From a44f4a82bc9b3ce318afda0b8ad38317ffcdc492 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Sat, 30 Apr 2016 12:48:05 +0200 Subject: [PATCH 15/17] Fix Yaml::parse in phpspec --- .../Bundle/MeasureBundle/Convert/MeasureConverterSpec.php | 3 +-- .../Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php b/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php index 9716b93..48046a2 100644 --- a/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php +++ b/spec/Akeneo/Bundle/MeasureBundle/Convert/MeasureConverterSpec.php @@ -18,8 +18,7 @@ function let() throw new \Exception(sprintf('Config file "%s" does not exist', $filename)); } - $config = Yaml::parse($filename); - + $config = Yaml::parse(file_get_contents($filename)); $this->beConstructedWith($config); } diff --git a/spec/Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php b/spec/Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php index 4cc325c..77d2182 100644 --- a/spec/Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php +++ b/spec/Akeneo/Bundle/MeasureBundle/Manager/MeasureManagerSpec.php @@ -21,7 +21,7 @@ function let() throw new \Exception(sprintf('Config file "%s" does not exist', $filename)); } - $config = Yaml::parse($filename); + $config = Yaml::parse(file_get_contents($filename)); $this->setMeasureConfig($config['measures_config']); } From 7534aa4b79441fbbd8843a7c7be927c5682e011f Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Sat, 30 Apr 2016 12:48:23 +0200 Subject: [PATCH 16/17] Travis: use new container infra --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index c141020..1814bec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ php: - "5.3" - "hhvm" +# Allow to use container infrastructure +sudo: false + before_script: - composer self-update - composer update From 4f47c0196209258fdaf827a0734b591e71c68563 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Sat, 30 Apr 2016 12:48:40 +0200 Subject: [PATCH 17/17] Bump phpspec version to 2.5.* --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 23a8131..6337950 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "symfony/symfony": ">=2.1.0" }, "require-dev": { - "phpspec/phpspec": "2.0.*@dev" + "phpspec/phpspec": "2.5.*" }, "config": { "bin-dir": "bin"