Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 1d56026

Browse files
committed
Merge branch 'feature/10' into develop
Close #10
2 parents 624730e + 76c0419 commit 1d56026

File tree

9 files changed

+174
-49
lines changed

9 files changed

+174
-49
lines changed

.travis.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ matrix:
1717
- php: 5.5
1818
env:
1919
- EXECUTE_CS_CHECK=true
20+
- php: 5.5
21+
env:
22+
- SERVICE_MANAGER_VERSION='^2.7.5'
2023
- php: 5.6
2124
env:
2225
- EXECUTE_TEST_COVERALLS=true
26+
- php: 5.6
27+
env:
28+
- SERVICE_MANAGER_VERSION='^2.7.5'
2329
- php: 7
24-
- php: hhvm
25-
allow_failures:
2630
- php: 7
31+
env:
32+
- SERVICE_MANAGER_VERSION='^2.7.5'
33+
- php: hhvm
34+
- php: hhvm
35+
env:
36+
- SERVICE_MANAGER_VERSION='^2.7.5'
37+
allow_failures:
38+
- php: hhvm
2739

2840
notifications:
2941
irc: "irc.freenode.org#zftalk.dev"
@@ -33,6 +45,8 @@ before_install:
3345
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
3446
- composer self-update
3547
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
48+
- if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
49+
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi
3650

3751
install:
3852
- travis_retry composer install --no-interaction --ignore-platform-reqs

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 3.0.0 - TBD
5+
## 2.6.0 - 2016-02-03
66

77
### Added
88

@@ -18,5 +18,6 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- [#3](https://github.com/zendframework/zend-tag/pull/3) updates the component
22-
to use zend-servicemanager v3.
21+
- [#3](https://github.com/zendframework/zend-tag/pull/3) and
22+
[#10](https://github.com/zendframework/zend-tag/pull/10) update the component
23+
to be forward-compatible with zend-servicemanager v3.

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
}
1414
},
1515
"require": {
16-
"php": ">=5.5",
17-
"zendframework/zend-escaper": "~2.5",
18-
"zendframework/zend-stdlib": "~2.5"
16+
"php": "^5.5 || ^7.0",
17+
"zendframework/zend-escaper": "^2.5",
18+
"zendframework/zend-stdlib": "^3.0"
1919
},
2020
"require-dev": {
21-
"zendframework/zend-config": "~2.5",
22-
"zendframework/zend-servicemanager": "dev-develop as 2.7.0",
21+
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
2322
"fabpot/php-cs-fixer": "1.7.*",
2423
"phpunit/PHPUnit": "~4.0"
2524
},
@@ -31,7 +30,7 @@
3130
"extra": {
3231
"branch-alias": {
3332
"dev-master": "2.5-dev",
34-
"dev-develop": "3.0-dev"
33+
"dev-develop": "2.6-dev"
3534
}
3635
},
3736
"autoload-dev": {

src/Cloud/DecoratorPluginManager.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
namespace Zend\Tag\Cloud;
1111

12+
use RuntimeException;
1213
use Zend\ServiceManager\AbstractPluginManager;
1314
use Zend\ServiceManager\Factory\InvokableFactory;
15+
use Zend\ServiceManager\Exception\InvalidServiceException;
1416

1517
/**
1618
* Plugin manager implementation for decorators.
@@ -37,7 +39,49 @@ class DecoratorPluginManager extends AbstractPluginManager
3739
protected $factories = [
3840
Decorator\HtmlCloud::class => InvokableFactory::class,
3941
Decorator\HtmlTag::class => InvokableFactory::class,
42+
// Legacy (v2) due to alias resolution; canonical form of resolved
43+
// alias is used to look up the factory, while the non-normalized
44+
// resolved alias is used as the requested name passed to the factory.
45+
'zendtagclouddecoratorhtmlcloud' => InvokableFactory::class,
46+
'zendtagclouddecoratorhtmltag' => InvokableFactory::class
4047
];
4148

4249
protected $instanceOf = Decorator\DecoratorInterface::class;
50+
51+
/**
52+
* Validate the plugin is of the expected type (v3).
53+
*
54+
* Validates against `$instanceOf`.
55+
*
56+
* @param mixed $instance
57+
* @throws InvalidServiceException
58+
*/
59+
public function validate($instance)
60+
{
61+
if (! $instance instanceof $this->instanceOf) {
62+
throw new InvalidServiceException(sprintf(
63+
'%s can only create instances of %s; %s is invalid',
64+
get_class($this),
65+
$this->instanceOf,
66+
(is_object($instance) ? get_class($instance) : gettype($instance))
67+
));
68+
}
69+
}
70+
71+
/**
72+
* Validate the plugin is of the expected type (v2).
73+
*
74+
* Proxies to `validate()`.
75+
*
76+
* @param mixed $instance
77+
* @throws InvalidServiceException
78+
*/
79+
public function validatePlugin($instance)
80+
{
81+
try {
82+
$this->validate($instance);
83+
} catch (InvalidServiceException $e) {
84+
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
85+
}
86+
}
4387
}

test/Cloud/CloudTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
namespace ZendTest\Tag\Cloud;
1111

12+
use ArrayObject;
1213
use stdClass;
1314
use Zend\ServiceManager\ServiceManager;
15+
use Zend\ServiceManager\Config as SMConfig;
1416
use Zend\Tag;
1517
use Zend\Tag\Cloud;
1618
use Zend\Tag\Cloud\Decorator\HtmlCloud;
@@ -228,9 +230,14 @@ public function testConstructorWithArray()
228230
$this->assertEquals('foo', $list[0]->getTitle());
229231
}
230232

233+
/**
234+
* This test uses ArrayObject, which will have essentially the
235+
* same behavior as Zend\Config\Config; the code is looking only
236+
* for a Traversable.
237+
*/
231238
public function testConstructorWithConfig()
232239
{
233-
$cloud = $this->getCloud(new \Zend\Config\Config([
240+
$cloud = $this->getCloud(new ArrayObject([
234241
'tags' => [
235242
[
236243
'title' => 'foo',
@@ -320,12 +327,21 @@ protected function getCloud($options = null, $setDecoratorPluginManager = true)
320327

321328
if ($setDecoratorPluginManager) {
322329
$decorators = $cloud->getDecoratorPluginManager();
330+
/*
323331
$decorators->configure([
324332
'invokables' => [
325333
'CloudDummy' => CloudDummy::class,
326334
'TagDummy' => TagDummy::class
327335
]
328336
]);
337+
*/
338+
$smConfig = new SMConfig([
339+
'invokables' => [
340+
'CloudDummy' => CloudDummy::class,
341+
'TagDummy' => TagDummy::class
342+
]
343+
]);
344+
$smConfig->configureServiceManager($decorators);
329345
}
330346

331347
return $cloud;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
namespace ZendTest\ServiceManager;
10+
11+
use PHPUnit_Framework_TestCase as TestCase;
12+
use Zend\ServiceManager\ServiceManager;
13+
use Zend\Tag\Cloud\DecoratorPluginManager;
14+
use Zend\Tag\Cloud\Decorator\DecoratorInterface;
15+
use Zend\ServiceManager\Test\CommonPluginManagerTrait;
16+
17+
/**
18+
* Example test of using CommonPluginManagerTrait
19+
*/
20+
class DecoratorPluginManagerCompatibilityTest extends TestCase
21+
{
22+
use CommonPluginManagerTrait;
23+
24+
protected function getPluginManager()
25+
{
26+
return new DecoratorPluginManager(new ServiceManager());
27+
}
28+
29+
protected function getV2InvalidPluginException()
30+
{
31+
return \RuntimeException::class;
32+
}
33+
34+
protected function getInstanceOf()
35+
{
36+
return DecoratorInterface::class;
37+
}
38+
}

test/Cloud/Decorator/HtmlCloudTest.php

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace ZendTest\Tag\Cloud\Decorator;
1111

12+
use ArrayObject;
1213
use Zend\Tag\Cloud\Decorator;
1314

1415
/**
@@ -72,58 +73,54 @@ public function testSeparator()
7273
public function testConstructorWithArray()
7374
{
7475
$decorator = new Decorator\HtmlCloud([
75-
'htmlTags' => ['div'],
76-
'separator' => ' '
77-
]);
76+
'htmlTags' => ['div'],
77+
'separator' => ' ',
78+
]);
7879

7980
$this->assertEquals(
80-
'<div>foo bar</div>', $decorator->render(
81-
[
82-
'foo',
83-
'bar'
84-
]
85-
)
81+
'<div>foo bar</div>',
82+
$decorator->render([
83+
'foo',
84+
'bar'
85+
])
8686
);
8787
}
8888

89+
/**
90+
* This test uses ArrayObject, which will have essentially the
91+
* same behavior as Zend\Config\Config; the code is looking only
92+
* for a Traversable.
93+
*/
8994
public function testConstructorWithConfig()
9095
{
91-
$decorator = new Decorator\HtmlCloud(
92-
new \Zend\Config\Config(
93-
[
94-
'htmlTags' => ['div'],
95-
'separator' => ' '
96-
]
97-
)
98-
);
96+
$decorator = new Decorator\HtmlCloud(new ArrayObject([
97+
'htmlTags' => ['div'],
98+
'separator' => ' '
99+
]));
99100

100101
$this->assertEquals(
101-
'<div>foo bar</div>', $decorator->render(
102-
[
103-
'foo',
104-
'bar'
105-
]
106-
)
102+
'<div>foo bar</div>',
103+
$decorator->render([
104+
'foo',
105+
'bar'
106+
])
107107
);
108108
}
109109

110110
public function testSetOptions()
111111
{
112112
$decorator = new Decorator\HtmlCloud();
113-
$decorator->setOptions(
114-
[
115-
'htmlTags' => ['div'],
116-
'separator' => ' '
117-
]
118-
);
113+
$decorator->setOptions([
114+
'htmlTags' => ['div'],
115+
'separator' => ' '
116+
]);
119117

120118
$this->assertEquals(
121-
'<div>foo bar</div>', $decorator->render(
122-
[
123-
'foo',
124-
'bar'
125-
]
126-
)
119+
'<div>foo bar</div>',
120+
$decorator->render([
121+
'foo',
122+
'bar'
123+
])
127124
);
128125
}
129126

test/Cloud/Decorator/HtmlTagTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace ZendTest\Tag\Cloud\Decorator;
1111

12+
use ArrayObject;
1213
use Zend\Tag;
1314
use Zend\Tag\Cloud\Decorator;
1415

@@ -114,9 +115,18 @@ public function testConstructorWithArray()
114115
$this->assertEquals('pt', $decorator->getFontSizeUnit());
115116
}
116117

118+
/**
119+
* This test uses ArrayObject, which will have essentially the
120+
* same behavior as Zend\Config\Config; the code is looking only
121+
* for a Traversable.
122+
*/
117123
public function testConstructorWithConfig()
118124
{
119-
$decorator = new Decorator\HtmlTag(new \Zend\Config\Config(['minFontSize' => 5, 'maxFontSize' => 10, 'fontSizeUnit' => 'pt']));
125+
$decorator = new Decorator\HtmlTag(new ArrayObject([
126+
'minFontSize' => 5,
127+
'maxFontSize' => 10,
128+
'fontSizeUnit' => 'pt',
129+
]));
120130

121131
$this->assertEquals(5, $decorator->getMinFontSize());
122132
$this->assertEquals(10, $decorator->getMaxFontSize());

test/ItemTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace ZendTest\Tag;
1111

12+
use ArrayObject;
1213
use Zend\Tag;
1314

1415
/**
@@ -108,9 +109,14 @@ public function testMissingWeight()
108109
$tag = new Tag\Item(['title' => 'foo']);
109110
}
110111

112+
/**
113+
* This test uses ArrayObject, which will have essentially the
114+
* same behavior as Zend\Config\Config; the code is looking only
115+
* for a Traversable.
116+
*/
111117
public function testConfigOptions()
112118
{
113-
$tag = new Tag\Item(new \Zend\Config\Config(['title' => 'foo', 'weight' => 1]));
119+
$tag = new Tag\Item(new ArrayObject(['title' => 'foo', 'weight' => 1]));
114120

115121
$this->assertEquals($tag->getTitle(), 'foo');
116122
$this->assertEquals($tag->getWeight(), 1);

0 commit comments

Comments
 (0)