Skip to content

Commit

Permalink
Merge branch 'master' into 3.next
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 1, 2018
2 parents c240540 + 8b0b88c commit b69b920
Show file tree
Hide file tree
Showing 26 changed files with 149 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
/phpunit.xml
/vendor
/.idea/
tests/test_app/App/Model/Table/CommentsTable.php
16 changes: 8 additions & 8 deletions .travis.yml
Expand Up @@ -3,8 +3,8 @@ language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

cache:
directories:
Expand All @@ -23,17 +23,17 @@ matrix:
fast_finish: true

include:
- php: 5.6
env: PREFER_LOWEST=1

- php: 7.1
env: RUN_CS=1 RUN_TESTS=0

- php: 7.1
env: PHPSTAN=1 RUN_TESTS=0

- php: 5.6
env: PREFER_LOWEST=1

before_install:
- if [[ $TRAVIS_PHP_VERSION != 7.1 ]]; then phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION != 7.3 ]]; then phpenv config-rm xdebug.ini; fi
- if [[ -n "$GH_TOKEN" ]]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
- if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
- if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
Expand All @@ -43,15 +43,15 @@ before_script:
- if [[ $PREFER_LOWEST = 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi

script:
- if [[ $RUN_TESTS = 1 && $TRAVIS_PHP_VERSION != 7.1 ]]; then vendor/bin/phpunit; fi
- if [[ $RUN_TESTS = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
- if [[ $RUN_TESTS = 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi
- if [[ $RUN_TESTS = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi

- if [[ $RUN_CS = 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi

- if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.9 && vendor/bin/phpstan analyse -c phpstan.neon -l 4 src; fi

after_success:
- if [[ $RUN_TESTS = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then bash <(curl -s https://codecov.io/bash); fi
- if [[ $RUN_TESTS = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi

notifications:
email: false
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -19,7 +19,7 @@
},
"require": {
"php": ">=5.6.0",
"cakephp/cakephp": "dev-3.next as 3.7.0",
"cakephp/cakephp": "^3.7.0",
"cakephp/plugin-installer": "^1.0",
"wyrihaximus/twig-view": "^4.3.4"
},
Expand Down
1 change: 0 additions & 1 deletion src/Shell/Task/ControllerTask.php
Expand Up @@ -142,7 +142,6 @@ public function bake($controllerName)

$data = compact(
'actions',
'admin',
'components',
'currentModelName',
'defaultModel',
Expand Down
2 changes: 1 addition & 1 deletion src/Shell/Task/FixtureTask.php
Expand Up @@ -366,7 +366,7 @@ protected function _generateRecords(TableSchema $table, $recordCount = 1)
} else {
$insert = "Lorem ipsum dolor sit amet";
if (!empty($fieldInfo['length'])) {
$insert = substr($insert, 0, (int)$fieldInfo['length'] - 2);
$insert = substr($insert, 0, (int)$fieldInfo['length'] > 2 ? (int)$fieldInfo['length'] - 2 : (int)$fieldInfo['length']);
}
}
break;
Expand Down
5 changes: 4 additions & 1 deletion src/Shell/Task/ModelTask.php
Expand Up @@ -556,9 +556,12 @@ public function getEntityPropertySchema(Table $model)

$schema = $model->getSchema();
foreach ($schema->columns() as $column) {
$columnSchema = $schema->getColumn($column);

$properties[$column] = [
'kind' => 'column',
'type' => $schema->getColumnType($column)
'type' => $columnSchema['type'],
'null' => $columnSchema['null'],
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Template/Bake/Element/Controller/edit.twig
Expand Up @@ -22,7 +22,7 @@
*
* @param string|null $id {{ singularHumanName }} id.
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Bake/Plugin/README.md.twig
Expand Up @@ -17,7 +17,7 @@

## Installation

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).
You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).

The recommended way to install composer packages is:

Expand Down
7 changes: 6 additions & 1 deletion src/View/Helper/DocBlockHelper.php
Expand Up @@ -98,7 +98,12 @@ public function buildEntityPropertyHintTypeMap(array $propertySchema)
$properties = [];
foreach ($propertySchema as $property => $info) {
if ($info['kind'] === 'column') {
$properties[$property] = $this->columnTypeToHintType($info['type']);
$type = $this->columnTypeToHintType($info['type']);
if (!empty($info['null'])) {
$type .= '|null';
}

$properties[$property] = $type;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/BakeArticlesFixture.php
Expand Up @@ -34,7 +34,7 @@ class BakeArticlesFixture extends TestFixture
'body' => 'text',
'rating' => ['type' => 'float', 'unsigned' => true, 'default' => 0.0, 'null' => false],
'score' => ['type' => 'decimal', 'unsigned' => true, 'default' => 0.0, 'null' => false],
'published' => ['type' => 'boolean', 'length' => 1, 'default' => false],
'published' => ['type' => 'boolean', 'length' => 1, 'default' => false, 'null' => false],
'created' => 'datetime',
'updated' => 'datetime',
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixture/BakeCommentsFixture.php
Expand Up @@ -33,8 +33,8 @@ class BakeCommentsFixture extends TestFixture
'bake_user_id' => ['type' => 'integer', 'null' => false],
'comment' => 'text',
'published' => ['type' => 'string', 'length' => 1, 'default' => 'N'],
'created' => 'datetime',
'updated' => 'datetime',
'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'updated' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['otherid']]]
];

Expand Down
1 change: 1 addition & 0 deletions tests/Fixture/BinaryTestsFixture.php
Expand Up @@ -29,6 +29,7 @@ class BinaryTestsFixture extends TestFixture
*/
public $fields = [
'id' => ['type' => 'integer'],
'byte' => ['type' => 'binary', 'length' => 1],
'data' => ['type' => 'binary', 'length' => 300],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
];
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/Shell/Task/FixtureTaskTest.php
Expand Up @@ -18,6 +18,8 @@
use Bake\Test\TestCase\TestCase;
use Cake\Console\Shell;
use Cake\Core\Plugin;
use Cake\Database\Driver\Postgres;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;

/**
Expand Down Expand Up @@ -362,10 +364,31 @@ public function testRecordGenerationForDatatypes()
*/
public function testRecordGenerationForBinaryType()
{
$driver = ConnectionManager::get('test')->getDriver();
$this->skipIf($driver instanceof Postgres, 'Incompatible with postgres');

$this->generatedFile = ROOT . 'tests/Fixture/BinaryTestsFixture.php';
$this->exec('bake fixture --connection test BinaryTests');

$this->assertFileContains("'data' => 'Lorem ipsum dolor sit amet'", $this->generatedFile);
$this->assertFileContains("'byte' => 'L'", $this->generatedFile);
}

/**
* test record generation with float and binary types
*
* @return void
*/
public function testRecordGenerationForBinaryTypePostgres()
{
$driver = ConnectionManager::get('test')->getDriver();
$this->skipIf(($driver instanceof Postgres) === false, 'Only compatible with postgres');

$this->generatedFile = ROOT . 'tests/Fixture/BinaryTestsFixture.php';
$this->exec('bake fixture --connection test BinaryTests');

$this->assertFileContains("'data' => 'Lorem ipsum dolor sit amet'", $this->generatedFile);
$this->assertFileContains("'byte' => 'Lorem ipsum dolor sit amet'", $this->generatedFile);
}

/**
Expand Down
93 changes: 69 additions & 24 deletions tests/TestCase/Shell/Task/ModelTaskTest.php
Expand Up @@ -626,40 +626,64 @@ public function testGetEntityPropertySchema()
$expected = [
'id' => [
'kind' => 'column',
'type' => 'integer'
'type' => 'integer',
'null' => false,
],
'title' => [
'kind' => 'column',
'type' => 'string'
'type' => 'string',
'null' => false,
],
'body' => [
'kind' => 'column',
'type' => 'text'
'type' => 'text',
'null' => true,
],
'rating' => [
'kind' => 'column',
'type' => 'float'
'type' => 'float',
'null' => false,
],
'score' => [
'kind' => 'column',
'type' => 'decimal'
'type' => 'decimal',
'null' => false,
],
'created' => [
'kind' => 'column',
'type' => 'timestamp'
'type' => 'timestamp',
'null' => true,
],
'bake_user_id' => [
'kind' => 'column',
'type' => 'integer'
'type' => 'integer',
'null' => false,
],
'published' => [
'kind' => 'column',
'type' => 'boolean'
'type' => 'boolean',
'null' => false,
],
'updated' => [
'kind' => 'column',
'type' => 'timestamp'
],
'type' => 'timestamp',
'null' => true
]
];
foreach ($expected as $key => $value) {
$this->assertArrayHasKey($key, $result);

$this->assertArrayHasKey('kind', $result[$key]);
$this->assertSame($value['kind'], $result[$key]['kind']);

$this->assertArrayHasKey('type', $result[$key]);
$this->assertSame($value['type'], $result[$key]['type']);

$this->assertArrayHasKey('null', $result[$key]);
$this->assertSame($value['null'], $result[$key]['null']);
}

$expectedAssociations = [
'bake_user' => [
'kind' => 'association',
'association' => $model->getAssociation('BakeUsers'),
Expand All @@ -671,7 +695,9 @@ public function testGetEntityPropertySchema()
'type' => '\BakeTest\Model\Entity\Author'
]
];
$this->assertEquals($expected, $result);
foreach ($expectedAssociations as $key => $expected) {
$this->assertEquals($expected, $result[$key]);
}
}

/**
Expand Down Expand Up @@ -862,7 +888,14 @@ public function testGetValidation()
],
'published' => [
'boolean' => ['rule' => 'boolean', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmpty', 'args' => []]
'requirePresence' => [
'rule' => 'requirePresence',
'args' => ["'create'" ],
],
'notEmpty' => [
'rule' => 'notEmpty',
'args' => [],
],
],
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
Expand Down Expand Up @@ -942,7 +975,8 @@ public function testGetValidationSigned()
],
'published' => [
'boolean' => ['rule' => 'boolean', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmpty', 'args' => []]
'notEmpty' => ['rule' => 'notEmpty', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
],
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
Expand Down Expand Up @@ -1097,6 +1131,10 @@ public function testGetValidationExcludeForeignKeys()
];
$result = $this->Task->getValidation($model, $associations);
$expected = [
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmpty', 'args' => ["'create'"]]
],
'title' => [
'scalar' => ['rule' => 'scalar', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
Expand All @@ -1107,14 +1145,6 @@ public function testGetValidationExcludeForeignKeys()
'scalar' => ['rule' => 'scalar', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmpty', 'args' => []]
],
'published' => [
'boolean' => ['rule' => 'boolean', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmpty', 'args' => []]
],
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmpty', 'args' => ["'create'"]]
],
'rating' => [
'numeric' => ['rule' => 'numeric', 'args' => []],
'greaterThanOrEqual' => [
Expand All @@ -1134,9 +1164,23 @@ public function testGetValidationExcludeForeignKeys()
0,
],
],
'notEmpty' => ['rule' => 'notEmpty', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
]
'notEmpty' => ['rule' => 'notEmpty', 'args' => []],
],
'published' => [
'boolean' => [
'rule' => 'boolean',
'args' => [],
],
'requirePresence' => [
'rule' => 'requirePresence',
'args' => ["'create'" ],
],
'notEmpty' => [
'rule' => 'notEmpty',
'args' => [],
],
],
];
$this->assertEquals($expected, $result);
}
Expand Down Expand Up @@ -1172,7 +1216,8 @@ public function testGetValidationExcludeForeignKeysSigned()
],
'published' => [
'boolean' => ['rule' => 'boolean', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmpty', 'args' => []]
'notEmpty' => ['rule' => 'notEmpty', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
],
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Controller/testBakeActions.php
Expand Up @@ -86,7 +86,7 @@ public function add()
*
* @param string|null $id Bake Article id.
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Controller/testBakeActionsContent.php
Expand Up @@ -70,7 +70,7 @@ public function add()
*
* @param string|null $id Bake Article id.
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/comparisons/Controller/testBakeWithPlugin.php
Expand Up @@ -71,7 +71,7 @@ public function add()
*
* @param string|null $id Bake Article id.
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null)
{
Expand Down

0 comments on commit b69b920

Please sign in to comment.