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

Commit f1ee9ae

Browse files
committed
Merge branch 'hotfix/31'
Close #31
2 parents 5debcc1 + d7bee91 commit f1ee9ae

4 files changed

Lines changed: 40 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
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.2 - TBD
5+
## 3.0.2 - 2016-09-06
66

77
### Added
88

@@ -25,6 +25,10 @@ All notable changes to this project will be documented in this file, in reverse
2525
prevents false negative assertions from occuring.
2626
- [#21](https://github.com/zendframework/zend-test/pull/21) updates the
2727
`sebastian/version` dependency to also allow v2.0 releases.
28+
- [#31](https://github.com/zendframework/zend-test/pull/31) fixes an issue with
29+
the `AbstractControllerTestCase` when used to test a console request.
30+
Previously, routes with multiple literal flags were never matched; they now
31+
are.
2832

2933
## 3.0.1 - 2016-06-15
3034

src/PHPUnit/Controller/AbstractControllerTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function url($url, $method = HttpRequest::METHOD_GET, $params = [])
232232
{
233233
$request = $this->getRequest();
234234
if ($this->useConsoleRequest) {
235-
preg_match_all('/(--\S+[= ]"[^\s"]*\s*[^\s"]*")|(--\S+=\S+|--\S+\s\S+|\S+)/', $url, $matches);
235+
preg_match_all('/(--\S+[= ]"[^\s"]*\s*[^\s"]*")|(\S+)/', $url, $matches);
236236
$params = str_replace([' "', '"'], ['=', ''], $matches[0]);
237237
$request->params()->exchangeArray($params);
238238

test/PHPUnit/Controller/AbstractConsoleControllerTestCaseTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,27 @@ public function testAssertMatchedArgumentsWithValueWithoutEqualsSign()
131131
$this->assertEquals("10", $routeMatch->getParam('id'));
132132
$this->assertEquals("custom text", $routeMatch->getParam('text'));
133133
}
134+
135+
public function testAssertMatchedArgumentsWithLiteralFlags()
136+
{
137+
$this->dispatch('literal --foo --bar');
138+
$routeMatch = $this->getApplication()->getMvcEvent()->getRouteMatch();
139+
$this->assertInstanceOf(RouteMatch::class, $routeMatch, 'Did not receive a route match?');
140+
$this->assertMatchedRouteName('arguments-literal');
141+
$this->assertTrue($routeMatch->getParam('foo'));
142+
$this->assertTrue($routeMatch->getParam('bar'));
143+
$this->assertFalse($routeMatch->getParam('optional'));
144+
$this->assertNull($routeMatch->getParam('doo'));
145+
146+
$this->reset();
147+
148+
$this->dispatch('literal --foo --bar --doo test');
149+
$routeMatch = $this->getApplication()->getMvcEvent()->getRouteMatch();
150+
$this->assertInstanceOf(RouteMatch::class, $routeMatch, 'Did not receive a route match?');
151+
$this->assertMatchedRouteName('arguments-literal');
152+
$this->assertTrue($routeMatch->getParam('foo'));
153+
$this->assertTrue($routeMatch->getParam('bar'));
154+
$this->assertFalse($routeMatch->getParam('optional'));
155+
$this->assertSame('test', $routeMatch->getParam('doo'));
156+
}
134157
}

test/_files/Baz/config/module.config.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@
3232
'action' => 'console',
3333
),
3434
),
35-
)
35+
),
36+
'arguments-literal' => array(
37+
'type' => 'simple',
38+
'options' => array(
39+
'route' => 'literal --foo [--bar] [--doo=] [--optional]',
40+
'defaults' => array(
41+
'controller' => 'baz_index',
42+
'action' => 'console',
43+
),
44+
),
45+
),
3646
),
3747
),
3848
),

0 commit comments

Comments
 (0)