Skip to content

Commit 22f7c0d

Browse files
committed
Work in progress on the PHPSPec extension
Signed-off-by: Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
1 parent 7ff0999 commit 22f7c0d

14 files changed

+543
-4
lines changed

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
sudo: false
2+
3+
language: php
4+
5+
php:
6+
- 5.6
7+
- 7.0
8+
9+
cache:
10+
directories:
11+
- vendor
12+
- bin
13+
14+
before_script:
15+
- rm composer.lock
16+
- composer self-update
17+
- composer install
18+
19+
script:
20+
- bin/phpcs
21+
- bin/phpmd src/ text cleancode,controversial,design,naming,codesize
22+
- bin/phpspec run --config phpspec.travis.yml
23+
24+
after_script:
25+
- bin/coveralls -v

RELEASE_NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# Release 1.0.0
1+
# Release 0.1.0
2+
23
Factory generator adapter for PHPSpec auto-wiring in `let()` or `it_*()` methods.

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"require": {
99
"php": "~5.6|>=7.0",
1010
"magento/framework": "~100.0",
11+
"zendframework/zend-stdlib": "~2.4.6",
12+
"zendframework/zend-code": "~2.4.6",
1113
"mikey179/vfsStream": "^1.6"
1214
},
1315
"require-dev": {
@@ -16,7 +18,8 @@
1618
"phpmd/phpmd": "^2.3",
1719
"satooshi/php-coveralls": "dev-master",
1820
"henrikbjorn/phpspec-code-coverage": "^2.0",
19-
"phpspec/nyan-formatters": "^1.0"
21+
"phpspec/nyan-formatters": "^1.0",
22+
"ecomdev/phpspec-file-matcher": "^1.0"
2023
},
2124
"license": "OSL-3.0",
2225
"authors": [

composer.lock

Lines changed: 207 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Compiler">
3+
<description>The coding standard for EcomDev packages.</description>
4+
5+
<file>src</file>
6+
7+
<arg value="np"/>
8+
9+
<!-- Include some additional sniffs from the Generic standard -->
10+
<rule ref="Generic.Commenting.DocComment"/>
11+
12+
<!-- Use Unix newlines -->
13+
<rule ref="Generic.Files.LineEndings">
14+
<properties>
15+
<property name="eolChar" value="\n"/>
16+
</properties>
17+
</rule>
18+
19+
<rule ref="PSR2"/>
20+
</ruleset>

spec/EntityGeneratorSpec.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace spec\EcomDev\PHPSpec\MagentoDiAdapter;
4+
5+
use EcomDev\PHPSpec\MagentoDiAdapter\EntityGeneratorInterface;
6+
use Magento\Framework\Code\Generator\EntityAbstract;
7+
use PhpSpec\ObjectBehavior;
8+
use Prophecy\Argument;
9+
10+
class EntityGeneratorSpec extends ObjectBehavior
11+
{
12+
/**
13+
* @var EntityAbstract
14+
*/
15+
private $entityGenerator;
16+
17+
function let(EntityAbstract $entityGenerator)
18+
{
19+
$this->entityGenerator = $entityGenerator;
20+
$this->beConstructedWith(
21+
function () {},
22+
'entity'
23+
);
24+
}
25+
26+
function it_implements_entity_generator_interface()
27+
{
28+
$this->shouldImplement(EntityGeneratorInterface::class);
29+
}
30+
31+
function it_should_support_class_that_is_prefixed_with_suffix_in_argument()
32+
{
33+
// Supporting
34+
$this->supports('Some\Class\Entity')->shouldReturn(true);
35+
$this->supports('Some\ClassEntity')->shouldReturn(true);
36+
37+
// Not supporting
38+
$this->supports('Some\ClassFactory')->shouldReturn(false);
39+
$this->supports('Some\Class\Factory')->shouldReturn(false);
40+
41+
// Should not allow word parts
42+
$this->supports('Some\Classentity')->shouldReturn(false);
43+
$this->supports('Some\EntityClass')->shouldReturn(false);
44+
}
45+
46+
function it_allow_suffixed_class_name_and_generates_it()
47+
{
48+
$this->entityGenerator->init('Some\Class', 'Some\ClassEntity')->shouldBeCalled();
49+
$this->entityGenerator->generate()->willReturn('path/to/SomeClassEntity.php')->shouldBeCalled();
50+
51+
$this->beConstructedWith($this->entityFactoryClosure(), 'entity');
52+
$this->generate('Some\ClassEntity')->shouldReturn('path/to/SomeClassEntity.php');
53+
}
54+
55+
function it_allow_separated_class_name_in_subnamespace_and_generates_it()
56+
{
57+
$this->entityGenerator->init('Some\Class', 'Some\Class\Entity')->shouldBeCalled();
58+
$this->entityGenerator->generate()->willReturn('path/to/SomeClassEntity.php')->shouldBeCalled();
59+
$this->beConstructedWith($this->entityFactoryClosure(), 'entity');
60+
$this->generate('Some\Class\Entity')->shouldReturn('path/to/SomeClassEntity.php');
61+
}
62+
63+
private function entityFactoryClosure()
64+
{
65+
return function ($sourceClass, $originalClass) {
66+
$generator = $this->entityGenerator->getWrappedObject();
67+
$generator->init($sourceClass, $originalClass);
68+
return $generator;
69+
};
70+
}
71+
}

spec/Fixture/ValidClass.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: ivan
5+
* Date: 23/05/16
6+
* Time: 13:58
7+
*/
8+
9+
namespace spec\EcomDev\PHPSpec\MagentoDiAdapter\Fixture;
10+
11+
12+
class ValidClass
13+
{
14+
15+
}

0 commit comments

Comments
 (0)