cakephp: Cannot describe `tableName`. It has 0 columns
This is a (multiple allowed):
-
bug
-
enhancement
-
feature-discussion (RFC)
-
CakePHP Version:
3.4.11 -
Platform and Target:
PHPUnit 6.2.3CLI runnervendor/bin/phpunit --filter=ExitLinksTableTest::testValidation
What you did
I wanted to test my tables validation method. So I created a new test case in /tests/TestCase/Model/ExitLinksTableTest.php.
<?php
namespace ExitLinks\Test\TestCase\Model;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
class ExitLinksTableTest extends TestCase
{
public $fixtures = ['plugin.exit_links.exit_links'];
public function testValidation()
{
// Must define connectionName otherwise it tries to use 'default' datasource.
$table = TableRegistry::get('ExitLinks.ExitLinks', ['connectionName' => 'test']);
$entity = $table->newEntity();
$requestData = [];
$result = $table->patchEntity($entity, $requestData);
$this->assertNotEmpty($entity->getErrors());
}
}
I copied the SQLite DNS setup from here to my /tests/bootstrap.php.
What happened
PHPUnit 6.2.3 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 109 ms, Memory: 8.00MB
There was 1 error:
1) ExitLinks\Test\TestCase\Model\ExitLinksTableTest::testValidation
Cake\Database\Exception: Cannot describe exit_links. It has 0 columns.
/Users/david/Sites/CakePHP-ExitLinks/vendor/cakephp/cakephp/src/Database/Schema/Collection.php:99
/Users/david/Sites/CakePHP-ExitLinks/vendor/cakephp/cakephp/src/ORM/Table.php:531
/Users/david/Sites/CakePHP-ExitLinks/vendor/cakephp/cakephp/src/ORM/Marshaller.php:68
/Users/david/Sites/CakePHP-ExitLinks/vendor/cakephp/cakephp/src/ORM/Marshaller.php:547
/Users/david/Sites/CakePHP-ExitLinks/vendor/cakephp/cakephp/src/ORM/Table.php:2491
/Users/david/Sites/CakePHP-ExitLinks/tests/TestCase/Model/ExitLinksTableTest.php:32
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
What you expected to happen
I expected that the fixture would create the database table and populate it. I also expected that the fixture would create the relevant schema from the $fields array for the table instance. So that when I used the table in my test the schema would exist.
How did I sidestep this issue?
I have to manually create an instance with the schema and connection defined.
TableRegistry::set('Examples', new ExamplesTable([
'connection' => ConnectionManager::get('test'),
'schema' => new TableSchema([
'id' => ['type' = 'int'],
'title' => ['type' => 'string']
])
]);
/cc @lorenzo As you asked me to submit on IRC 😄
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 27 (20 by maintainers)
davidyell, please include the CakePHP version number you are using in your description. It helps us debug your issue.
– Automated response by Var.CI 🤖
Thread hijack!