|
19 | 19 | use Cake\Database\SchemaCache;
|
20 | 20 | use Cake\Database\Schema\CachedCollection;
|
21 | 21 | use Cake\Datasource\ConnectionManager;
|
| 22 | +use Cake\ORM\Entity; |
22 | 23 | use Cake\TestSuite\TestCase;
|
23 | 24 |
|
24 | 25 | /**
|
@@ -217,11 +218,35 @@ public function testGetSchemaWithConnectionInstance()
|
217 | 218 | * Test passing invalid object
|
218 | 219 | *
|
219 | 220 | * @expectedException \TypeError
|
220 |
| - * @expectedExceptionMessage Cake\Database\SchemaCache::getSchema() must implement interface Cake\Datasource\ConnectionInterface |
221 | 221 | * @return void
|
222 | 222 | */
|
223 |
| - public function testPassingInvalidObject() |
| 223 | + public function testPassingInvalidObjectPhp7() |
224 | 224 | {
|
225 |
| - new SchemaCache(new \SimpleXMLElement('')); |
| 225 | + $this->skipIf(phpversion() < 7.0); |
| 226 | + new SchemaCache(new Entity()); |
| 227 | + } |
| 228 | + |
| 229 | + /** |
| 230 | + * Test passing invalid object |
| 231 | + * |
| 232 | + * @return void |
| 233 | + */ |
| 234 | + public function testPassingInvalidObjectPhp56() |
| 235 | + { |
| 236 | + $this->skipIf(phpversion() > 7.0); |
| 237 | + |
| 238 | + $capture = function ($errno, $msg) { |
| 239 | + restore_error_handler(); |
| 240 | + $this->assertEquals(E_RECOVERABLE_ERROR, $errno); |
| 241 | + $this->assertContains('Argument 1 passed to Cake\Database\SchemaCache::getSchema() must implement interface Cake\Datasource\ConnectionInterface, instance of Cake\ORM\Entity given', $msg); |
| 242 | + }; |
| 243 | + set_error_handler($capture); |
| 244 | + |
| 245 | + try { |
| 246 | + new SchemaCache(new Entity()); |
| 247 | + $this->fail('Exception not thrown'); |
| 248 | + } catch (\RuntimeException $e) { |
| 249 | + $this->assertEquals('The given connection object is not compatible with schema caching, as it does not implement a "schemaCollection()" method.', $e->getMessage()); |
| 250 | + } |
226 | 251 | }
|
227 | 252 | }
|
0 commit comments