cakephp-3.0

phpunit mock - method does not exist

蹲街弑〆低调 提交于 2019-12-22 04:38:07
问题 I recently updated PHPunit from 5.3 to 5.5 in an IntegrationTestCase of an app that is CakePhp 3.x based. and I don't understand how to update my mock generation scripts. Originally I created my mock like this: $stub = $this->getMock('SomeClass', array('execute')); $stub->method('execute') ->will($this->returnValue($this->returnUrl)); After the change to PHPUnit 5.5 this got me the following warning: PHPUnit_Framework_TestCase::getMock() is deprecated, use PHPUnit_Framework_TestCase:

CakePHP 3 - Query builder properly not working for HasMany associations

走远了吗. 提交于 2019-12-22 01:31:16
问题 Table : Services +-----+--------------+ | id | title | +-----+--------------+ | 1 | Service 1 | +-----+--------------+ | 2 | Service 2 | +-----+--------------+ Table : Workshops { HasMany WorkshopServices } +-----+---------------+ | id | title | +-----+---------------+ | 1 | Workshop 1 | +-----+---------------+ | 2 | Workshop 2 | +-----+---------------+ Table : WorkshopServices +-----+--------------+-------------+ | id | workshop_id | service_id | +-----+--------------+-------------+ | 1 | 1

cakephp 3.x saving multiple entities - newEntities

☆樱花仙子☆ 提交于 2019-12-21 16:45:34
问题 I'm having the hardest time with saving multiple records. I've tried a million things, but I end up with the same problem: my records are not saved and I can't see any errors. Bear in mind that I'm new to cakephp and a novice coder. Am I missing something obvious and crucial? Table: $this->table('splits'); $this->displayField('id'); $this->primaryKey('id'); $this->belongsTo('Transactions', [ 'foreignKey' => 'transaction_id', 'joinType' => 'INNER' ]); $this->belongsTo('Accounts', [ 'foreignKey

Virtual fields with Cakephp 3

孤者浪人 提交于 2019-12-21 04:49:22
问题 I need to have a virtual property in my user entity. I followed the CakePHP book. UserEntity.php namespace App\Model\Entity; use Cake\ORM\Entity; class User extends Entity { protected $_virtual = ['full_name']; protected function _getFullName() { return $this->_properties['firstname'] . ' ' . $this->_properties['lastname']; } } In a controller $users = TableRegistry::get('Users'); $user = $users->get(29); $firstname = $user->firstname; // $firstname: "John" $lastname = $user->lastname; //

CakePHP 3 - Compare passwords

做~自己de王妃 提交于 2019-12-21 04:42:35
问题 I have two field "password" (This field is in the database) and confirm_password (This field is not in the database) Well, I need to compare if password == confirm_password.. but I'm not knowing create a custom validation to "confirm_password"... Would need to have this field in the database? How do I do? 回答1: Generally you can access all data in a custom validation rule via the $context argument, where it's stored in the data key, ie $context['data']['confirm_password'] , which you could

cakephp 3.0 how to populate a select field with values instead of id

北战南征 提交于 2019-12-20 23:26:48
问题 i was looking for a previous answer, but the ones i've found are related to older cakephp versions i have two tables, 'magazines' and 'issues' where there is a relation 'issues' BelongsTo 'magazines', this is what IssuesTable looks like: public function initialize(array $config){ $this->belongsTo('Magazines', [ 'foreignKey' => 'id' ]); } table magazines has two fields, magazines.id and magazines.name table issues has two fields, issues.id, issues.magazine_id where issues.magazine_id is the

Setting up CakePHP 3 Plugin testing

£可爱£侵袭症+ 提交于 2019-12-20 16:22:03
问题 I've used bin/cake bake plugin PluginName to create a plugin. Part of it is that it creates phpunit.xml.dist , but bake doesn't create the folder structure or tests/bootstrap.php file that's required. The Problem I get a "No tests executed" message when I run phpunit : $ phpunit PHPUnit 5.1.3 by Sebastian Bergmann and contributors. Time: 239 ms, Memory: 4.50Mb No tests executed! Background information I've created my tests in my plugin folder under tests/TestCase . I don't think they are the

Setting up CakePHP 3 Plugin testing

落爺英雄遲暮 提交于 2019-12-20 16:21:37
问题 I've used bin/cake bake plugin PluginName to create a plugin. Part of it is that it creates phpunit.xml.dist , but bake doesn't create the folder structure or tests/bootstrap.php file that's required. The Problem I get a "No tests executed" message when I run phpunit : $ phpunit PHPUnit 5.1.3 by Sebastian Bergmann and contributors. Time: 239 ms, Memory: 4.50Mb No tests executed! Background information I've created my tests in my plugin folder under tests/TestCase . I don't think they are the

SQLSTATE HY000 2002 while running bake command

我与影子孤独终老i 提交于 2019-12-20 09:44:45
问题 I have problem running the bake commands. i think it is related to mysql but i didn't find any solution to this error on Stackoverflow. This is my app.php : 'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', //'port' => 'nonstandard_port_number', 'username' => 'root', 'password' => 'root', 'database' => 'laboiterose', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' =>

Error when retrieving associated data on. Linux only

拈花ヽ惹草 提交于 2019-12-20 06:38:58
问题 Prior this problem I had another issue related to the same subject. The problem has been sorted thanks ta @ndm. Link the previous problem: Cakephp 3. Windows and Linux OS returning different result when querying the database I have an article page and I am retrieving the associated data with articles. Article comments. I have the following line of code $this->Articles->find()->contain('ArticleComments'); This line of code on both local Windows 10 machine and production Debian server retrieves