Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing tests for SchemaCache to work with php 7.x and 5.6
  • Loading branch information
burzum committed Aug 19, 2017
1 parent 24c85fb commit 9a24084
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/Database/SchemaCache.php
Expand Up @@ -99,11 +99,7 @@ public function clear($name = null)
public function getSchema(ConnectionInterface $connection)
{
if (!method_exists($connection, 'schemaCollection')) {
throw new RuntimeException(sprintf(
'The "%s" connection is not compatible with schema caching, ' .
'as it does not implement a "schemaCollection()" method.',
$connection->configName()
));
throw new RuntimeException('The given connection object is not compatible with schema caching, as it does not implement a "schemaCollection()" method.');
}

$config = $connection->config();
Expand Down
31 changes: 28 additions & 3 deletions tests/TestCase/Database/SchemaCacheTest.php
Expand Up @@ -19,6 +19,7 @@
use Cake\Database\SchemaCache;
use Cake\Database\Schema\CachedCollection;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\Entity;
use Cake\TestSuite\TestCase;

/**
Expand Down Expand Up @@ -217,11 +218,35 @@ public function testGetSchemaWithConnectionInstance()
* Test passing invalid object
*
* @expectedException \TypeError
* @expectedExceptionMessage Cake\Database\SchemaCache::getSchema() must implement interface Cake\Datasource\ConnectionInterface
* @return void
*/
public function testPassingInvalidObject()
public function testPassingInvalidObjectPhp7()
{
new SchemaCache(new \SimpleXMLElement(''));
$this->skipIf(phpversion() < 7.0);
new SchemaCache(new Entity());
}

/**
* Test passing invalid object
*
* @return void
*/
public function testPassingInvalidObjectPhp56()
{
$this->skipIf(phpversion() > 7.0);

$capture = function ($errno, $msg) {
restore_error_handler();
$this->assertEquals(E_RECOVERABLE_ERROR, $errno);
$this->assertContains('Argument 1 passed to Cake\Database\SchemaCache::getSchema() must implement interface Cake\Datasource\ConnectionInterface, instance of Cake\ORM\Entity given', $msg);
};
set_error_handler($capture);

try {
new SchemaCache(new Entity());
$this->fail('Exception not thrown');
} catch (\RuntimeException $e) {
$this->assertEquals('The given connection object is not compatible with schema caching, as it does not implement a "schemaCollection()" method.', $e->getMessage());
}
}
}

0 comments on commit 9a24084

Please sign in to comment.