This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/view-model-support' into develop
Forward port #185
- Loading branch information
Showing
5 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
*/ | ||
|
||
namespace ZendTest\Expressive\Template; | ||
|
||
use ArrayIterator; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
use stdClass; | ||
use Zend\Expressive\Exception\InvalidArgumentException; | ||
|
||
class ArrayParametersTraitTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->subject = new TestAsset\ArrayParameters(); | ||
} | ||
|
||
public function testNullParamsAreReturnedAsEmptyArray() | ||
{ | ||
$this->assertEquals([], $this->subject->normalize(null)); | ||
} | ||
|
||
public function testArrayParamsAreReturnedVerbatim() | ||
{ | ||
$params = ['foo' => 'bar']; | ||
$this->assertSame($params, $this->subject->normalize($params)); | ||
} | ||
|
||
public function testExtractsVariablesFromObjectsImplementingGetVariables() | ||
{ | ||
$params = ['foo' => 'bar']; | ||
$model = new TestAsset\ViewModel($params); | ||
$this->assertSame($params, $this->subject->normalize($model)); | ||
} | ||
|
||
public function testCastsTraversablesToArrays() | ||
{ | ||
$params = ['foo' => 'bar']; | ||
$model = new ArrayIterator($params); | ||
$this->assertSame($params, $this->subject->normalize($model)); | ||
} | ||
|
||
public function testCastsObjectsToArrays() | ||
{ | ||
$params = ['foo' => 'bar']; | ||
$model = (object) $params; | ||
$this->assertSame($params, $this->subject->normalize($model)); | ||
} | ||
|
||
public function nonNullScalarParameters() | ||
{ | ||
// @codingStandardsIgnoreStart | ||
// [scalar, expected exception string] | ||
return [ | ||
'true' => [true, 'bool'], | ||
'false' => [false, 'bool'], | ||
'zero' => [0, 'int'], | ||
'int' => [1, 'int'], | ||
'zero-float' => [0.0, 'double'], | ||
'float' => [1.1, 'double'], | ||
'string' => ['view param', 'string'], | ||
]; | ||
// @codingStandardsIgnoreEnd | ||
} | ||
|
||
/** | ||
* @dataProvider nonNullScalarParameters | ||
*/ | ||
public function testNonNullScalarsRaiseAnException($scalar, $expectedString) | ||
{ | ||
$this->setExpectedException(InvalidArgumentException::class, $expectedString); | ||
$this->subject->normalize($scalar); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
*/ | ||
|
||
namespace ZendTest\Expressive\Template\TestAsset; | ||
|
||
use Zend\Expressive\Template\ArrayParametersTrait; | ||
|
||
class ArrayParameters | ||
{ | ||
use ArrayParametersTrait; | ||
|
||
public function normalize($params) | ||
{ | ||
return $this->normalizeParams($params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
*/ | ||
|
||
namespace ZendTest\Expressive\Template\TestAsset; | ||
|
||
class ViewModel | ||
{ | ||
private $variables; | ||
|
||
public function __construct(array $variables) | ||
{ | ||
$this->variables = $variables; | ||
} | ||
|
||
public function getVariables() | ||
{ | ||
return $this->variables; | ||
} | ||
} |