/** * @test */ public function setMasterReplicaGetMasterReplica() { $config = new ConfigService(); $config->addMaster($this->_correct1); $config->addReplica($this->_correct2); $this->assertSame($this->_correct1, $config->getMaster()); $this->assertSame($this->_correct2, $config->getReplica()); }
/** * @test */ public function closeOpenedConnectionMasterOverride() { $config = new ConfigService(); $config->addMaster($this->_db_config1); $config->addReplica($this->_db_config2); $connect = $this->getMockBuilder(ConnectionService::class)->setMethods(['_createConnection'])->setConstructorArgs([$config])->getMock(); $callback = function () { return new PPDO(); }; $connect->expects($this->any())->method('_createConnection')->will($this->returnCallback($callback)); // Order here is important, otherwise master will be returned in both cases $connect->getReplica(); $master = $connect->getMaster(); $replica = $connect->getReplica(); // Master override in effect $this->assertSame($master, $replica); $this->assertEquals(2, $connect->closeOpenedConnections()); $this->assertEquals(0, $connect->closeOpenedConnections()); }