Permalink
Browse files

Merge branch 'release/1.0.0'

  • Loading branch information...
2 parents 3ef1e3a + 586d8ee commit a306f60ca50052959c0595e9b0e9c0e2e61b302f @IvanChepurnyi IvanChepurnyi committed Jan 13, 2013
Showing with 3,961 additions and 137 deletions.
  1. +1 −1 .travis.yml
  2. +56 −1 README.md
  3. +58 −0 app/code/community/Hackathon/FixtureGenerator/Helper/Data.php
  4. +26 −18 app/code/community/Hackathon/FixtureGenerator/Model/Generator/Abstract.php
  5. +116 −0 app/code/community/Hackathon/FixtureGenerator/Model/Generator/Container.php
  6. +22 −3 app/code/community/Hackathon/FixtureGenerator/Model/Generator/Container/Interface.php
  7. +31 −6 app/code/community/Hackathon/FixtureGenerator/Model/Generator/Increment.php
  8. +41 −0 app/code/community/Hackathon/FixtureGenerator/Model/Generator/Interface.php
  9. +34 −11 app/code/community/Hackathon/FixtureGenerator/Model/Generator/Random.php
  10. +52 −17 app/code/community/Hackathon/FixtureGenerator/Model/Generator/Range.php
  11. +43 −0 app/code/community/Hackathon/FixtureGenerator/Model/Generator/Variable.php
  12. +113 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor.php
  13. +146 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Abstract.php
  14. +65 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Category.php
  15. +74 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Customer.php
  16. +77 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Customer/Address.php
  17. +32 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Interface.php
  18. +85 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Product.php
  19. +85 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Product/Abstract.php
  20. +45 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Product/Bundle.php
  21. +43 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Product/Configurable.php
  22. +44 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Product/Downloadable.php
  23. +43 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Product/Grouped.php
  24. +35 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Product/Simple.php
  25. +44 −0 app/code/community/Hackathon/FixtureGenerator/Model/Processor/Product/Virtual.php
  26. +39 −0 app/code/community/Hackathon/FixtureGenerator/Test/Helper/Data.php
  27. +40 −0 app/code/community/Hackathon/FixtureGenerator/Test/Helper/Data/expectations/testUpdatePathValue.yaml
  28. +23 −0 app/code/community/Hackathon/FixtureGenerator/Test/Helper/Data/providers/testUpdatePathValue.yaml
  29. +29 −17 app/code/community/Hackathon/FixtureGenerator/Test/Model/Generator/Abstract.php
  30. +6 −0 ...community/Hackathon/FixtureGenerator/Test/Model/Generator/Abstract/providers/testConstructor.yaml
  31. +187 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Generator/Container.php
  32. +21 −0 ...ommunity/Hackathon/FixtureGenerator/Test/Model/Generator/Container/expectations/testGenerate.yaml
  33. +21 −0 ...munity/Hackathon/FixtureGenerator/Test/Model/Generator/Container/expectations/testInitialize.yaml
  34. +9 −0 ...e/community/Hackathon/FixtureGenerator/Test/Model/Generator/Container/providers/testGenerate.yaml
  35. +8 −0 ...community/Hackathon/FixtureGenerator/Test/Model/Generator/Container/providers/testInitialize.yaml
  36. +32 −4 app/code/community/Hackathon/FixtureGenerator/Test/Model/Generator/Increment.php
  37. +5 −5 ...ommunity/Hackathon/FixtureGenerator/Test/Model/Generator/Increment/expectations/testGenerate.yaml
  38. +26 −13 app/code/community/Hackathon/FixtureGenerator/Test/Model/Generator/Random.php
  39. +5 −2 ...e/community/Hackathon/FixtureGenerator/Test/Model/Generator/Random/expectations/testGenerate.yaml
  40. +10 −6 ...code/community/Hackathon/FixtureGenerator/Test/Model/Generator/Random/providers/testGenerate.yaml
  41. +31 −9 app/code/community/Hackathon/FixtureGenerator/Test/Model/Generator/Range.php
  42. +24 −2 ...de/community/Hackathon/FixtureGenerator/Test/Model/Generator/Range/expectations/testGenerate.yaml
  43. +9 −1 app/code/community/Hackathon/FixtureGenerator/Test/Model/Generator/Range/providers/testGenerate.yaml
  44. +38 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Generator/Variable.php
  45. +2 −0 ...community/Hackathon/FixtureGenerator/Test/Model/Generator/Variable/expectations/testGenerate.yaml
  46. +6 −0 ...de/community/Hackathon/FixtureGenerator/Test/Model/Generator/Variable/providers/testGenerate.yaml
  47. +95 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor.php
  48. +137 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract.php
  49. +4 −0 ...nity/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/expectations/testGetConfigPath.yaml
  50. +10 −0 ...ity/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/expectations/testGetDefaultData.yaml
  51. +7 −0 ...ty/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/expectations/testGetDefaultValue.yaml
  52. +15 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/fixtures/config.yaml
  53. +10 −0 ...de/community/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/providers/testGenerate.yaml
  54. +8 −0 ...mmunity/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/providers/testGetConfigPath.yaml
  55. +12 −0 ...munity/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/providers/testGetDefaultData.yaml
  56. +15 −0 ...unity/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/providers/testGetDefaultValue.yaml
  57. +10 −0 ...unity/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/providers/testGetRequiredKeys.yaml
  58. +10 −0 .../community/Hackathon/FixtureGenerator/Test/Model/Processor/Abstract/providers/testInitialize.yaml
  59. +37 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Category.php
  60. +19 −0 .../community/Hackathon/FixtureGenerator/Test/Model/Processor/Category/expectations/testProcess.yaml
  61. +7 −0 ...ode/community/Hackathon/FixtureGenerator/Test/Model/Processor/Category/providers/testProcess.yaml
  62. +37 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Customer.php
  63. +37 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Customer/Address.php
  64. +48 −0 ...ty/Hackathon/FixtureGenerator/Test/Model/Processor/Customer/Address/expectations/testProcess.yaml
  65. +10 −0 ...unity/Hackathon/FixtureGenerator/Test/Model/Processor/Customer/Address/providers/testProcess.yaml
  66. +36 −0 .../community/Hackathon/FixtureGenerator/Test/Model/Processor/Customer/expectations/testProcess.yaml
  67. +9 −0 ...ode/community/Hackathon/FixtureGenerator/Test/Model/Processor/Customer/providers/testProcess.yaml
  68. +37 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product.php
  69. +57 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Bundle.php
  70. +63 −0 ...nity/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Bundle/expectations/testProcess.yaml
  71. +19 −0 ...mmunity/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Bundle/providers/testProcess.yaml
  72. +57 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Configurable.php
  73. +69 −0 ...ackathon/FixtureGenerator/Test/Model/Processor/Product/Configurable/expectations/testProcess.yaml
  74. +20 −0 ...y/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Configurable/providers/testProcess.yaml
  75. +58 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Downloadable.php
  76. +69 −0 ...ackathon/FixtureGenerator/Test/Model/Processor/Product/Downloadable/expectations/testProcess.yaml
  77. +24 −0 ...y/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Downloadable/providers/testProcess.yaml
  78. +57 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Grouped.php
  79. +69 −0 ...ity/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Grouped/expectations/testProcess.yaml
  80. +20 −0 ...munity/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Grouped/providers/testProcess.yaml
  81. +57 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Simple.php
  82. +75 −0 ...nity/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Simple/expectations/testProcess.yaml
  83. +20 −0 ...mmunity/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Simple/providers/testProcess.yaml
  84. +57 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Virtual.php
  85. +34 −0 ...ity/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Virtual/expectations/testProcess.yaml
  86. +4 −0 ...munity/Hackathon/FixtureGenerator/Test/Model/Processor/Product/Virtual/providers/testProcess.yaml
  87. +150 −0 ...e/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product/expectations/testProcess.yaml
  88. +42 −0 ...code/community/Hackathon/FixtureGenerator/Test/Model/Processor/Product/providers/testProcess.yaml
  89. +66 −0 ...nity/Hackathon/FixtureGenerator/Test/Model/Processor/expectations/testFixtureBasedGeneration.yaml
  90. +19 −0 ...e/community/Hackathon/FixtureGenerator/Test/Model/Processor/expectations/testRealFixtureLoad.yaml
  91. +6 −0 app/code/community/Hackathon/FixtureGenerator/Test/Model/Processor/fixtures/generate.yaml
  92. +14 −0 ...mmunity/Hackathon/FixtureGenerator/Test/Model/Processor/providers/testFixtureBasedGeneration.yaml
  93. +180 −15 app/code/community/Hackathon/FixtureGenerator/etc/config.xml
  94. +24 −1 app/etc/modules/Hackathon_FixtureGenerator.xml
  95. +39 −5 composer.json
View
@@ -2,8 +2,8 @@ language: php
php:
- 5.3
before_install:
- - composer install --dev
- mkdir test/
+ - composer install --dev
before_script:
- CURR_DIR=$(pwd)
- bin/mage-ci install test 1.7.0.2 magento_test -c -t -r http://mage-ci.ecomdev.org
View
@@ -1,3 +1,58 @@
-Hackathon-FixtureGenerator
+Hackathon_FixtureGenerator
+==========================
[![Build Status](https://travis-ci.org/magento-hackathon/Hackathon-FixtureGenerator.png?branch=master)](https://travis-ci.org/magento-hackathon/Hackathon-FixtureGenerator)
+
+Facts
+-----
+- version: 1.0.0
+- extension key: Hackathon_FixtureGenerator
+- [extension on GitHub](https://github.com/magento-hackathon/Hackathon-FixtureGenerator)
+
+Description
+-----------
+This module generates fixtures for your PHPUnit tests with Magento on-the-fly.
+
+Requirements
+------------
+- PHP >= 5.3.0
+- EcomDev_PHPUnit - https://github.com/IvanChepurnyi/EcomDev_PHPUnit
+
+Compatibility
+-------------
+- Magento >= 1.4
+
+Installation Instructions
+-------------------------
+1. Copy all the files of this repository into your Magento document root.
+2. Clear the cache, logout from the admin panel and then login again.
+3. Specify the fixtures you want to generate.
+4. Run phpunit in your Magento document root.
+
+Uninstallation
+--------------
+1. Remove all extension files from your Magento installation
+
+Support
+-------
+If you have any issues with this extension, open an issue on [GitHub](https://github.com/magento-hackathon/Hackathon-FixtureGenerator/issues).
+
+Contribution
+------------
+Any contribution is highly appreciated. The best way to contribute code is to open a [pull request on GitHub](https://help.github.com/articles/using-pull-requests).
+
+Developers
+----------
+- Peter Jaap Blaakmeer - [@peterjaap](https://twitter.com/peterjaap)
+- Ivan Chepurnyi - [@IvanChepurnyi](https://twitter.com/IvanChepurnyi)
+- Dima Janzen - [@dimajanzen](https://twitter.com/dimajanzen)
+- Rouven Alexander Rieker - [@therouv](https://twitter.com/therouv)
+- Michael Ryvlin - [@mryvlin](https://twitter.com/mryvlin)
+
+Licence
+-------
+[OSL - Open Software Licence 3.0](http://opensource.org/licenses/osl-3.0.php)
+
+Copyright
+---------
+(c) 2013 Magento Hackathon Dev Team
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Fixture Generator module for PHP Unit test suite for Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * @category Hackathon
+ * @package Hackathon_FixtureGenerator
+ * @author Peter Jaap Blaakmeer <https://github.com/peterjaap>
+ * @author Ivan Chepurnyi <https://github.com/IvanChepurnyi>
+ * @author Dima Janzen <https://github.com/dimajanzen>
+ * @author Rouven Alexander Rieker <https://github.com/therouv>
+ * @author Michael Ryvlin <https://github.com/mryvlin>
+ * @copyright 2013 Hackathon Dev Team (http://www.magento-hackathon.de/)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @link https://github.com/magento-hackathon/Hackathon-FixtureGenerator/
+ */
+/**
+ * Helper class
+ */
+class Hackathon_FixtureGenerator_Helper_Data extends Mage_Core_Helper_Abstract
+{
+ /**
+ * @param $path
+ * @param $value
+ * @param $array
+ * @return Hackathon_FixtureGenerator_Helper_Data
+ */
+ public function updatePathValue($path, $value, &$array)
+ {
+ $path = preg_split('/(?<!\\\\)\\//', $path);
+
+ $currentItem = &$array;
+
+ for ($i = 0, $length=count($path); $i < $length; $i++) {
+ $key = strtr($path[$i], array('\\/' => '/'));
+ $nextKey = isset($path[$i+1]) ? $path[$i+1] : false;
+
+ if ((!isset($currentItem[$key])
+ || !is_array($currentItem[$key]))
+ && $nextKey) {
+ // If not the last element create path array
+ $currentItem[$key] = array();
+ } elseif (!$nextKey) {
+ $currentItem[$key] = $value;
+ }
+
+ $currentItem = &$currentItem[$key];
+ }
+
+ return $this;
+ }
+}
@@ -1,6 +1,30 @@
<?php
-
+/**
+ * Fixture Generator module for PHP Unit test suite for Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * @category Hackathon
+ * @package Hackathon_FixtureGenerator
+ * @author Peter Jaap Blaakmeer <https://github.com/peterjaap>
+ * @author Ivan Chepurnyi <https://github.com/IvanChepurnyi>
+ * @author Dima Janzen <https://github.com/dimajanzen>
+ * @author Rouven Alexander Rieker <https://github.com/therouv>
+ * @author Michael Ryvlin <https://github.com/mryvlin>
+ * @copyright 2013 Hackathon Dev Team (http://www.magento-hackathon.de/)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @link https://github.com/magento-hackathon/Hackathon-FixtureGenerator/
+ */
+/**
+ * Abstract generator
+ */
abstract class Hackathon_FixtureGenerator_Model_Generator_Abstract
+ implements Hackathon_FixtureGenerator_Model_Generator_Interface
{
protected $format;
@@ -9,20 +33,4 @@ public function __construct($format)
$this->format = $format;
}
- public function generate(array $data)
- {
- $generatedString = $this->format;
- if (preg_match_all('/\\{\\$(.*)\\}/', $this->format, $vars)) {
- foreach ($vars[1] as $index => $variableName) {
- if (isset($data[$variableName])) {
- $value = $data[$variableName];
- } else {
- $value = '';
- }
-
- $generatedString = str_replace($vars[0][$index], $value, $generatedString);
- }
- }
- return $generatedString;
- }
-}
+}
@@ -0,0 +1,116 @@
+<?php
+/**
+ * Fixture Generator module for PHP Unit test suite for Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * @category Hackathon
+ * @package Hackathon_FixtureGenerator
+ * @author Peter Jaap Blaakmeer <https://github.com/peterjaap>
+ * @author Ivan Chepurnyi <https://github.com/IvanChepurnyi>
+ * @author Dima Janzen <https://github.com/dimajanzen>
+ * @author Rouven Alexander Rieker <https://github.com/therouv>
+ * @author Michael Ryvlin <https://github.com/mryvlin>
+ * @copyright 2013 Hackathon Dev Team (http://www.magento-hackathon.de/)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @link https://github.com/magento-hackathon/Hackathon-FixtureGenerator/
+ */
+class Hackathon_FixtureGenerator_Model_Generator_Container
+ implements Hackathon_FixtureGenerator_Model_Generator_Container_Interface
+{
+ protected static $generators = array();
+
+ /**
+ * Generator values
+ *
+ * @var Hackathon_FixtureGenerator_Model_Generator_Interface[]
+ */
+ protected $value = array();
+
+ /**
+ * Adds processor class
+ *
+ * @param string $type
+ * @param string $className
+ */
+ public static function add($type, $className)
+ {
+ self::$generators[$type] = $className;
+ }
+
+ /**
+ * Removes processor by type
+ *
+ * @param string $type
+ */
+ public static function remove($type)
+ {
+ if (isset(self::$generators[$type])) {
+ unset(self::$generators[$type]);
+ }
+ }
+
+ /**
+ * Initializes string generators
+ *
+ *
+ */
+ public static function initializeGenerators()
+ {
+ if (empty(self::$generators)) {
+ self::add('$', 'Hackathon_FixtureGenerator_Model_Generator_Variable');
+ self::add('increment', 'Hackathon_FixtureGenerator_Model_Generator_Increment');
+ self::add('random', 'Hackathon_FixtureGenerator_Model_Generator_Random');
+ self::add('range', 'Hackathon_FixtureGenerator_Model_Generator_Range');
+ }
+ }
+
+ /**
+ * @param string $string
+ *
+ * @return Hackathon_FixtureGenerator_Model_Generator_Container
+ */
+ public function initialize($string)
+ {
+ self::initializeGenerators();
+ $this->value = array();
+ $unParsedValue = preg_split('/(?<!\\\\)\\|/', $string);
+ foreach ($unParsedValue as $item) {
+ $item = strtr($item, array('\\|' => '|'));
+ foreach (self::$generators as $type => $className) {
+ if (strpos($item, '{' . $type) !== false) {
+ $this->value[] = new $className($item);
+ continue 2;
+ }
+ }
+ $this->value[] = $item;
+ }
+ return $this;
+ }
+
+ /**
+ * Generates a string with data of row
+ *
+ * @param array $data
+ *
+ * @return string
+ */
+ public function generate($data)
+ {
+ $result = '';
+ foreach ($this->value as $generator) {
+ if ($generator instanceof Hackathon_FixtureGenerator_Model_Generator_Interface) {
+ $result .= $generator->generate($data);
+ } else {
+ $result .= $generator;
+ }
+ }
+
+ return $result;
+ }
+}
@@ -1,6 +1,25 @@
<?php
-
-
+/**
+ * Fixture Generator module for PHP Unit test suite for Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * @category Hackathon
+ * @package Hackathon_FixtureGenerator
+ * @author Peter Jaap Blaakmeer <https://github.com/peterjaap>
+ * @author Ivan Chepurnyi <https://github.com/IvanChepurnyi>
+ * @author Dima Janzen <https://github.com/dimajanzen>
+ * @author Rouven Alexander Rieker <https://github.com/therouv>
+ * @author Michael Ryvlin <https://github.com/mryvlin>
+ * @copyright 2013 Hackathon Dev Team (http://www.magento-hackathon.de/)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @link https://github.com/magento-hackathon/Hackathon-FixtureGenerator/
+ */
/**
* Generator interface for fixture generator
*
@@ -32,4 +51,4 @@ public function initialize($string);
*/
public function generate($rowData);
-}
+}
@@ -1,5 +1,25 @@
<?php
-
+/**
+ * Fixture Generator module for PHP Unit test suite for Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ *
+ * @category Hackathon
+ * @package Hackathon_FixtureGenerator
+ * @author Peter Jaap Blaakmeer <https://github.com/peterjaap>
+ * @author Ivan Chepurnyi <https://github.com/IvanChepurnyi>
+ * @author Dima Janzen <https://github.com/dimajanzen>
+ * @author Rouven Alexander Rieker <https://github.com/therouv>
+ * @author Michael Ryvlin <https://github.com/mryvlin>
+ * @copyright 2013 Hackathon Dev Team (http://www.magento-hackathon.de/)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @link https://github.com/magento-hackathon/Hackathon-FixtureGenerator/
+ */
class Hackathon_FixtureGenerator_Model_Generator_Increment extends Hackathon_FixtureGenerator_Model_Generator_Abstract
{
/**
@@ -8,6 +28,11 @@ class Hackathon_FixtureGenerator_Model_Generator_Increment extends Hackathon_Fix
protected $increment;
/**
+ * @var string
+ */
+ protected $placeholder;
+
+ /**
* Class constructor; sets the increment value
* @param $format
* @return void
@@ -16,9 +41,10 @@ public function __construct($format)
{
$this->format = $format;
- if (preg_match_all('/\\{increment\:(.*)\\}/', $format, $vars)) {
- $increment = $vars[1][0];
+ if (preg_match('/\\{increment\:(.*)\\}/', $format, $vars)) {
+ $increment = $vars[1];
$this->increment = $increment;
+ $this->placeholder = $vars[0];
}
}
@@ -30,8 +56,7 @@ public function __construct($format)
*/
public function generate(array $data)
{
- $increment = $this->increment;
- $this->increment++;
- return $increment;
+ $value = str_replace($this->placeholder, $this->increment++, $this->format);
+ return $value;
}
}
Oops, something went wrong.

0 comments on commit a306f60

Please sign in to comment.