Permalink
Browse files

! Added fist test

  • Loading branch information...
1 parent b43d03a commit 35f59ad87a0f5b41de27d44bdda3115042379073 @IvanChepurnyi IvanChepurnyi committed Jan 12, 2013
@@ -0,0 +1,28 @@
+<?php
+
+abstract class Hackathon_FixtureGenerator_Model_Generator_Abstract
+{
+ protected $format;
+
+ 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,25 @@
+<?php
+
+class Hackathon_FixtureGenerator_Test_Model_Generator_Abstract extends EcomDev_PHPUnit_Test_Case
+{
+ protected $generator = null;
+
+ protected function setUp()
+ {
+
+ }
+
+ /**
+ *
+ *
+ * @param array $currentRow
+ * @param string $string
+ * @dataProvider dataProvider
+ */
+ public function testGenerate(array $currentRow, $string)
+ {
+ $this->generator = $this->getMockForAbstractClass('Hackathon_FixtureGenerator_Model_Generator_Abstract', array($string));
+ $dataSet = $this->readAttribute($this, 'dataName');
+ $this->assertEquals($this->expected()->getData($dataSet), $this->generator->generate($currentRow));
+ }
+}
@@ -0,0 +1,2 @@
+test_replacement: sku1
+test_replacement_empty: sku
@@ -0,0 +1,6 @@
+test_replacement:
+ - id: 1
+ - sku{$id}
+test_replacement_empty:
+ - key: 1
+ - sku{$id}
@@ -3,7 +3,7 @@
<phpunit>
<suite>
<modules>
- <MagentoHackathon_FixtureGenerator />
+ <Hackathon_FixtureGenerator />
</modules>
</suite>
</phpunit>
View
4 modman
@@ -1,2 +1,2 @@
-app/code/community/Hackathon/FixtureGenerator app/code/community/MagentoHackathon/FixtureGenerator
-app/etc/modules/Hackathon_FixtureGenerator.xml app/etc/modules/MagentoHackathon_FixtureGenerator.xml
+app/code/community/Hackathon/FixtureGenerator app/code/community/Hackathon/FixtureGenerator
+app/etc/modules/Hackathon_FixtureGenerator.xml app/etc/modules/Hackathon_FixtureGenerator.xml

0 comments on commit 35f59ad

Please sign in to comment.