|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Maatify\DataAdapters\Tests\Adapters; |
| 6 | + |
| 7 | +use Maatify\DataAdapters\Adapters\MySQL\MySQLDBALAdapter; |
| 8 | +use Maatify\DataAdapters\Contracts\Adapter\AdapterInterface; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | + |
| 11 | +class MySQLDBALAdapterTest extends TestCase |
| 12 | +{ |
| 13 | + protected function setUp(): void |
| 14 | + { |
| 15 | + if (! class_exists('Doctrine\DBAL\Connection')) { |
| 16 | + $this->markTestSkipped('Doctrine DBAL Connection class is not available.'); |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + public function test_it_implements_adapter_interface(): void |
| 21 | + { |
| 22 | + $driver = $this->createStub('Doctrine\DBAL\Connection'); |
| 23 | + $adapter = new MySQLDBALAdapter($driver); |
| 24 | + |
| 25 | + $this->assertInstanceOf(AdapterInterface::class, $adapter); |
| 26 | + } |
| 27 | + |
| 28 | + public function test_construction_and_get_driver(): void |
| 29 | + { |
| 30 | + $driver = $this->createStub('Doctrine\DBAL\Connection'); |
| 31 | + $adapter = new MySQLDBALAdapter($driver); |
| 32 | + |
| 33 | + $this->assertSame($driver, $adapter->getDriver()); |
| 34 | + } |
| 35 | + |
| 36 | + public function test_get_driver_returns_correct_type(): void |
| 37 | + { |
| 38 | + $driver = $this->createStub('Doctrine\DBAL\Connection'); |
| 39 | + $adapter = new MySQLDBALAdapter($driver); |
| 40 | + |
| 41 | + $this->assertInstanceOf('Doctrine\DBAL\Connection', $adapter->getDriver()); |
| 42 | + } |
| 43 | + |
| 44 | + public function test_repeated_calls_return_same_instance(): void |
| 45 | + { |
| 46 | + $driver = $this->createStub('Doctrine\DBAL\Connection'); |
| 47 | + $adapter = new MySQLDBALAdapter($driver); |
| 48 | + |
| 49 | + $first = $adapter->getDriver(); |
| 50 | + $second = $adapter->getDriver(); |
| 51 | + |
| 52 | + $this->assertSame($first, $second); |
| 53 | + } |
| 54 | +} |
0 commit comments