-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from FriendsOfCake/field-formatter
Add ability to set field formatters based on column type.
- Loading branch information
Showing
10 changed files
with
286 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,42 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
|
||
env: | ||
global: | ||
- DEFAULT=1 | ||
|
||
matrix: | ||
fast_finish: true | ||
|
||
include: | ||
- php: 7.0 | ||
env: PHPCS=1 | ||
env: PHPCS=1 DEFAULT=0 | ||
|
||
- php: 7.0 | ||
env: PHPSTAN=1 | ||
env: PHPSTAN=1 DEFAULT=0 | ||
|
||
before_script: | ||
- if [[ $TRAVIS_PHP_VERSION != 7.0 ]]; then phpenv config-rm xdebug.ini; fi | ||
|
||
- composer install --prefer-dist --no-interaction | ||
|
||
- if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:dev-master; fi | ||
- if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan:^0.8; fi | ||
|
||
script: | ||
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi | ||
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi | ||
|
||
- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ config/; fi | ||
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 5 src; fi | ||
|
||
after_success: | ||
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi | ||
|
||
notifications: | ||
email: false |
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
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,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
bootstrap="./tests/bootstrap.php" | ||
> | ||
<php> | ||
<ini name="memory_limit" value="-1"/> | ||
</php> | ||
|
||
<!-- Add any additional test suites you want to run here --> | ||
<testsuites> | ||
<testsuite name="CrudView Tests"> | ||
<directory>./tests/TestCase</directory> | ||
</testsuite> | ||
<!-- Add plugin test suites here. --> | ||
</testsuites> | ||
|
||
<!-- Setup a listener for fixtures --> | ||
<listeners> | ||
<listener | ||
class="\Cake\TestSuite\Fixture\FixtureInjector" | ||
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php"> | ||
<arguments> | ||
<object class="\Cake\TestSuite\Fixture\FixtureManager" /> | ||
</arguments> | ||
</listener> | ||
</listeners> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">./src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,35 @@ | ||
<?php | ||
namespace CrudView\Test\TestCase\View; | ||
|
||
use Cake\TestSuite\TestCase; | ||
use CrudView\View\CrudView; | ||
|
||
/** | ||
* ViewTest class | ||
*/ | ||
class ViewTest extends TestCase | ||
{ | ||
public function testCreation() | ||
{ | ||
$CrudView = new CrudView( | ||
null, | ||
null, | ||
null, | ||
[ | ||
'helpers' => [ | ||
'CrudView' => [ | ||
'className' => 'CrudView.CrudView', | ||
'fieldFormatters' => ['datetime' => 'formatTime'] | ||
] | ||
] | ||
] | ||
); | ||
|
||
$expected = [ | ||
'className' => 'CrudView.CrudView', | ||
'fieldFormatters' => ['datetime' => 'formatTime'], | ||
]; | ||
$result = $CrudView->CrudView->getConfig(); | ||
$this->assertEquals($expected, $result); | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
namespace CrudView\Test\TestCase\View\Helper; | ||
|
||
use Cake\I18n\FrozenTime; | ||
use Cake\TestSuite\TestCase; | ||
use Cake\View\View; | ||
use CrudView\View\Helper\CrudViewHelper; | ||
|
||
/** | ||
* CrudViewHelperTest class | ||
*/ | ||
class CrudViewHelperTest extends TestCase | ||
{ | ||
/** | ||
* Helper to be tested | ||
* | ||
* @var \Cake\View\Helper\CrudViewHelper | ||
*/ | ||
public $CrudView; | ||
|
||
/** | ||
* Mocked view | ||
* | ||
* @var \Cake\View\View|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
public $View; | ||
|
||
/** | ||
* setUp method | ||
* | ||
* @return void | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->View = $this->getMockBuilder(View::class) | ||
->setMethods() | ||
->getMock(); | ||
|
||
static::setAppNamespace(); | ||
} | ||
|
||
public function testIntrospect() | ||
{ | ||
$this->CrudView = $this->getMockBuilder(CrudViewHelper::class) | ||
->setConstructorArgs([$this->View]) | ||
->setMethods(['columnType']) | ||
->getMock(); | ||
|
||
$this->CrudView | ||
->expects($this->any()) | ||
->method('columnType') | ||
->with('created') | ||
->will($this->returnValue('datetime')); | ||
|
||
$value = new FrozenTime(); | ||
$result = $this->CrudView->introspect('created', $value); | ||
$this->assertEquals('just now', $result); | ||
|
||
$this->CrudView->setConfig('fieldFormatters', [ | ||
'datetime' => 'formatTime', | ||
]); | ||
$result = $this->CrudView->introspect('created', $value); | ||
$this->assertEquals($this->CrudView->Time->nice($value), $result); | ||
|
||
$this->CrudView->setConfig('fieldFormatters', [ | ||
'datetime' => function () { | ||
return 'formatted time'; | ||
}, | ||
]); | ||
$result = $this->CrudView->introspect('created', $value); | ||
$this->assertEquals('formatted time', $result); | ||
} | ||
} |
Oops, something went wrong.