Skip to content

Commit 5d66f29

Browse files
authored
Merge pull request #160 from maxbaldanza/upgrade-to-phpspec4
Upgrade to phpspec4
2 parents 38e2bf7 + 7f354bd commit 5d66f29

23 files changed

+146
-439
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ dist: trusty
66

77
matrix:
88
include:
9-
- php: 5.6
109
- php: 7.0
1110
- php: 7.1
11+
- php: 7.2
1212
env: ANALYSIS='true'
13-
- php: hhvm
14-
- php: 5.6
13+
- php: 7.0
1514
env: COMPOSER_ARGS='--prefer-lowest'
1615
- php: nightly
16+
env: COMPOSER_ARGS='--ignore-platform-reqs'
1717
allow_failures:
1818
- php: nightly
1919

composer.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
"type": "library",
66
"license": "MIT",
77
"require": {
8-
"php": "^5.6 || ^7.0",
9-
"phpspec/phpspec": "^3.0 <3.5.0",
10-
"symfony/dependency-injection": "^2.7 || ^3.0",
11-
"symfony/config": "^2.7 || ^3.0",
8+
"php": "^7.0",
9+
"phpspec/phpspec": "^4.0 <4.1.0",
10+
"phpspec/prophecy": "^1.6",
11+
"symfony/dependency-injection": "^3.2",
12+
"symfony/config": "^3.2",
1213
"shanethehat/pretty-xml": "~1.0.2"
1314
},
1415
"require-dev": {
1516
"magetest/magento": "~1.8.1.0",
16-
"behat/behat": "~3.0",
17-
"phpunit/phpunit": "^4.0|^5.0",
17+
"behat/behat": "~3.3",
18+
"phpunit/phpunit": "^5.7|^6.0",
1819
"squizlabs/php_codesniffer": "^3.0"
1920
},
2021
"config": {

features/bootstrap/Fake/YesPrompter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class YesPrompter implements Prompter
1111
* @param boolean $default
1212
* @return boolean
1313
*/
14-
public function askConfirmation($question, $default = true)
14+
public function askConfirmation(string $question, bool $default = true) : bool
1515
{
1616
return true;
1717
}

features/bootstrap/FeatureContext.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use OutputSpecification\ObjectSpecification;
77
use OutputSpecification\SpecSpecification;
88
use PhpSpec\Console\Application;
9+
use PHPUnit\Framework\Assert;
910
use Symfony\Component\Console\Tester\ApplicationTester;
1011
use Symfony\Component\Filesystem\Filesystem;
1112

@@ -274,7 +275,7 @@ public function aModelClassShouldBeGenerated()
274275
public function thereIsANewModule()
275276
{
276277
$this->moduleName = $moduleName = 'Unique' . self::$uniqueCount;
277-
PHPUnit_Framework_Assert::assertFileNotExists("public/app/code/local/Behat/$moduleName");
278+
Assert::assertFileNotExists("public/app/code/local/Behat/$moduleName");
278279
}
279280

280281
/**
@@ -326,7 +327,7 @@ public function theConfigXmlFileShouldContainAnElement($objectType)
326327
throw new \RuntimeException('Element not found in config XML');
327328
}
328329

329-
PHPUnit_Framework_Assert::assertEquals($expectedClass, (string) $result[0]);
330+
Assert::assertEquals($expectedClass, (string) $result[0]);
330331
}
331332

332333
/**
@@ -436,7 +437,7 @@ private function checkSpecIsCorrect(SpecSpecification $specSpecification)
436437

437438
$generatedSpec = file_get_contents($specSpecification->getFilePath());
438439

439-
PHPUnit_Framework_Assert::assertEquals($expectedSpec, $generatedSpec);
440+
Assert::assertEquals($expectedSpec, $generatedSpec);
440441
}
441442

442443
private function getTemplate($objectType)

spec/MageTest/PhpSpec/MagentoExtension/ExtensionSpec.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -194,28 +194,28 @@ protected function service($class, $container)
194194

195195
class FakeIndexedServiceContainer implements ServiceContainer
196196
{
197-
public function setParam($id, $value)
197+
public function setParam(string $id, $value)
198198
{}
199199

200-
public function getParam($id, $default = null)
200+
public function getParam(string $id, $default = null)
201201
{}
202202

203-
public function set($id, $service, $tags = [])
203+
public function set(string $id, $service, array $tags = [])
204204
{}
205205

206-
public function define($id, callable $definition, $tags = [])
206+
public function define(string $id, callable $definition, array $tags = [])
207207
{}
208208

209-
public function get($id)
209+
public function get(string $id)
210210
{}
211211

212-
public function has($id)
212+
public function has(string $id): bool
213213
{}
214214

215-
public function remove($id)
215+
public function remove(string $id)
216216
{}
217217

218-
public function getByTag($tag)
218+
public function getByTag(string $tag): array
219219
{}
220220

221221
public function addConfigurator($configurator)

spec/MageTest/PhpSpec/MagentoExtension/Listener/ModuleUpdateListenerSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function it_extracts_class_names_from_event_exceptions(ExampleEvent $event, Clas
3030
{
3131
$event->getException()->willReturn($exception);
3232

33+
$exception->getClassname()->willReturn('Vendor_Module_Model_Foo');
34+
3335
$this->getClassNameAfterExample($event);
3436

3537
$exception->getClassname()->shouldHaveBeenCalled();

src/MageTest/PhpSpec/MagentoExtension/CodeGenerator/Generator/BlockGenerator.php

+7-32
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,23 @@
3535
*/
3636
class BlockGenerator extends MagentoObjectGenerator implements GeneratorInterface
3737
{
38-
/**
39-
* @param ResourceInterface $resource
40-
* @param string $generation
41-
* @param array $data
42-
* @return bool
43-
*/
44-
public function supports(ResourceInterface $resource, $generation, array $data)
38+
39+
public function supports(ResourceInterface $resource, string $generation, array $data): bool
4540
{
4641
return 'class' === $generation && $resource instanceof BlockResource;
4742
}
4843

49-
/**
50-
* @return int
51-
*/
52-
public function getPriority()
44+
public function getPriority(): int
5345
{
5446
return 30;
5547
}
5648

57-
/**
58-
* @param ResourceInterface $resource
59-
*
60-
* @return string
61-
*/
62-
protected function getFilePath(ResourceInterface $resource)
49+
protected function getFilePath(ResourceInterface $resource): string
6350
{
6451
return $resource->getSrcFilename();
6552
}
6653

67-
/**
68-
* @param ResourceInterface $resource
69-
* @param string $filepath
70-
*
71-
* @return string
72-
*/
73-
protected function getGeneratedMessage(ResourceInterface $resource, $filepath)
54+
protected function getGeneratedMessage(ResourceInterface $resource, string $filepath): string
7455
{
7556
return sprintf(
7657
"<info>Magento block <value>%s</value> created in <value>'%s'</value>.</info>\n",
@@ -79,18 +60,12 @@ protected function getGeneratedMessage(ResourceInterface $resource, $filepath)
7960
);
8061
}
8162

82-
/**
83-
* @return string
84-
*/
85-
protected function getParentClass()
63+
protected function getParentClass(): string
8664
{
8765
return 'Mage_Core_Block_Abstract';
8866
}
8967

90-
/**
91-
* @return string
92-
*/
93-
protected function getTemplateName()
68+
protected function getTemplateName(): string
9469
{
9570
return 'mage_block';
9671
}

src/MageTest/PhpSpec/MagentoExtension/CodeGenerator/Generator/ControllerGenerator.php

+6-32
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,22 @@
3535
*/
3636
class ControllerGenerator extends MagentoObjectGenerator implements GeneratorInterface
3737
{
38-
/**
39-
* @param ResourceInterface $resource
40-
* @param string $generation
41-
* @param array $data
42-
* @return bool
43-
*/
44-
public function supports(ResourceInterface $resource, $generation, array $data)
38+
public function supports(ResourceInterface $resource, string $generation, array $data): bool
4539
{
4640
return 'class' === $generation && $resource instanceof ControllerResource;
4741
}
4842

49-
/**
50-
* @return int
51-
*/
52-
public function getPriority()
43+
public function getPriority(): int
5344
{
5445
return 10;
5546
}
5647

57-
/**
58-
* @param ResourceInterface $resource
59-
*
60-
* @return string
61-
*/
62-
protected function getFilePath(ResourceInterface $resource)
48+
protected function getFilePath(ResourceInterface $resource): string
6349
{
6450
return $resource->getSrcFilename();
6551
}
6652

67-
/**
68-
* @param ResourceInterface $resource
69-
* @param string $filepath
70-
*
71-
* @return string
72-
*/
73-
protected function getGeneratedMessage(ResourceInterface $resource, $filepath)
53+
protected function getGeneratedMessage(ResourceInterface $resource, string $filepath): string
7454
{
7555
return sprintf(
7656
"<info>Magento controller <value>%s</value> created in <value>'%s'</value>.</info>\n",
@@ -79,18 +59,12 @@ protected function getGeneratedMessage(ResourceInterface $resource, $filepath)
7959
);
8060
}
8161

82-
/**
83-
* @return string
84-
*/
85-
protected function getParentClass()
62+
protected function getParentClass(): string
8663
{
8764
return 'Mage_Core_Controller_Front_Action';
8865
}
8966

90-
/**
91-
* @return string
92-
*/
93-
protected function getTemplateName()
67+
protected function getTemplateName(): string
9468
{
9569
return 'mage_controller';
9670
}

src/MageTest/PhpSpec/MagentoExtension/CodeGenerator/Generator/ControllerSpecificationGenerator.php

+5-28
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,22 @@ class ControllerSpecificationGenerator extends PromptingGenerator implements Gen
1010
{
1111
const SUPPORTED_GENERATOR = 'controller_specification';
1212

13-
/**
14-
* @param ResourceInterface $resource
15-
* @param string $generation
16-
* @param array $data
17-
* @return bool
18-
*/
19-
public function supports(ResourceInterface $resource, $generation, array $data)
13+
public function supports(ResourceInterface $resource, string $generation, array $data): bool
2014
{
2115
return self::SUPPORTED_GENERATOR === $generation;
2216
}
2317

24-
public function getPriority()
18+
public function getPriority(): int
2519
{
2620
return 0;
2721
}
2822

29-
/**
30-
* @param ResourceInterface $resource
31-
*
32-
* @return string
33-
*/
34-
protected function getFilePath(ResourceInterface $resource)
23+
protected function getFilePath(ResourceInterface $resource): string
3524
{
3625
return $resource->getSpecFilename();
3726
}
3827

39-
/**
40-
* @param ResourceInterface $resource
41-
* @param string $filepath
42-
*
43-
* @return string
44-
*/
45-
protected function renderTemplate(ResourceInterface $resource, $filepath)
28+
protected function renderTemplate(ResourceInterface $resource, string $filepath): string
4629
{
4730
$values = [
4831
'%filepath%' => $filepath,
@@ -61,13 +44,7 @@ protected function renderTemplate(ResourceInterface $resource, $filepath)
6144
return $content;
6245
}
6346

64-
/**
65-
* @param ResourceInterface $resource
66-
* @param string $filepath
67-
*
68-
* @return string
69-
*/
70-
protected function getGeneratedMessage(ResourceInterface $resource, $filepath)
47+
protected function getGeneratedMessage(ResourceInterface $resource, string $filepath): string
7148
{
7249
return sprintf(
7350
"<info>ControllerSpecification for <value>%s</value> created in <value>'%s'</value>.</info>\n",

src/MageTest/PhpSpec/MagentoExtension/CodeGenerator/Generator/HelperGenerator.php

+7-32
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,23 @@
3535
*/
3636
class HelperGenerator extends MagentoObjectGenerator implements GeneratorInterface
3737
{
38-
/**
39-
* @param ResourceInterface $resource
40-
* @param string $generation
41-
* @param array $data
42-
* @return bool
43-
*/
44-
public function supports(ResourceInterface $resource, $generation, array $data)
38+
39+
public function supports(ResourceInterface $resource, string $generation, array $data): bool
4540
{
4641
return 'class' === $generation && $resource instanceof HelperResource;
4742
}
4843

49-
/**
50-
* @return int
51-
*/
52-
public function getPriority()
44+
public function getPriority(): int
5345
{
5446
return 20;
5547
}
5648

57-
/**
58-
* @param ResourceInterface $resource
59-
*
60-
* @return string
61-
*/
62-
protected function getFilePath(ResourceInterface $resource)
49+
protected function getFilePath(ResourceInterface $resource): string
6350
{
6451
return $resource->getSrcFilename();
6552
}
6653

67-
/**
68-
* @param ResourceInterface $resource
69-
* @param string $filepath
70-
*
71-
* @return string
72-
*/
73-
protected function getGeneratedMessage(ResourceInterface $resource, $filepath)
54+
protected function getGeneratedMessage(ResourceInterface $resource, string $filepath): string
7455
{
7556
return sprintf(
7657
"<info>Magento helper <value>%s</value> created in <value>'%s'</value>.</info>\n",
@@ -79,18 +60,12 @@ protected function getGeneratedMessage(ResourceInterface $resource, $filepath)
7960
);
8061
}
8162

82-
/**
83-
* @return string
84-
*/
85-
protected function getParentClass()
63+
protected function getParentClass(): string
8664
{
8765
return 'Mage_Core_Helper_Abstract';
8866
}
8967

90-
/**
91-
* @return string
92-
*/
93-
protected function getTemplateName()
68+
protected function getTemplateName(): string
9469
{
9570
return 'mage_helper';
9671
}

0 commit comments

Comments
 (0)