|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace Migrations\Test\TestCase\Migration; |
| 5 | + |
| 6 | +use Cake\Console\ConsoleIo; |
| 7 | +use Cake\Console\TestSuite\StubConsoleInput; |
| 8 | +use Cake\Console\TestSuite\StubConsoleOutput; |
| 9 | +use Cake\Datasource\ConnectionManager; |
| 10 | +use Migrations\Migration\ManagerFactory; |
| 11 | +use PHPUnit\Framework\TestCase; |
| 12 | + |
| 13 | +class ManagerFactoryTest extends TestCase |
| 14 | +{ |
| 15 | + public function testConnection(): void |
| 16 | + { |
| 17 | + $this->out = new StubConsoleOutput(); |
| 18 | + $this->out->setOutputAs(StubConsoleOutput::PLAIN); |
| 19 | + $this->in = new StubConsoleInput([]); |
| 20 | + |
| 21 | + $io = new ConsoleIo($this->out, $this->out, $this->in); |
| 22 | + |
| 23 | + $factory = new ManagerFactory(['connection' => 'test']); |
| 24 | + $result = $factory->createManager($io); |
| 25 | + |
| 26 | + $this->assertSame('test', $result->getConfig()->getConnection()); |
| 27 | + } |
| 28 | + |
| 29 | + public function testDsnConnection(): void |
| 30 | + { |
| 31 | + $this->out = new StubConsoleOutput(); |
| 32 | + $this->out->setOutputAs(StubConsoleOutput::PLAIN); |
| 33 | + $this->in = new StubConsoleInput([]); |
| 34 | + |
| 35 | + $io = new ConsoleIo($this->out, $this->out, $this->in); |
| 36 | + |
| 37 | + $factory = new ManagerFactory(['connection' => 'mysql://root@127.0.0.1/db_tmp']); |
| 38 | + $result = $factory->createManager($io); |
| 39 | + |
| 40 | + $this->assertSame('tmp', $result->getConfig()->getConnection()); |
| 41 | + $expected = [ |
| 42 | + 'scheme' => 'mysql', |
| 43 | + 'username' => 'root', |
| 44 | + 'host' => '127.0.0.1', |
| 45 | + 'className' => 'Cake\Database\Connection', |
| 46 | + 'database' => 'db_tmp', |
| 47 | + 'driver' => 'Cake\Database\Driver\Mysql', |
| 48 | + 'name' => 'tmp', |
| 49 | + ]; |
| 50 | + $this->assertEquals($expected, ConnectionManager::getConfig('tmp')); |
| 51 | + } |
| 52 | +} |
0 commit comments