/**
  * Test client db resources auto load by looping over 2 clients and pulling in
  * a remote active active record belonging to a client db resource without
  * having first defined the connection in the connection manager
  */
 public function testLoopThroughDifferentClientsAutoActiveRecordDbResource()
 {
     $dbFactory = \Yii::$app->get('dbFactory');
     $clients = Client::find()->orderBy('id')->all();
     foreach ($clients as $client) {
         $this->assertInstanceOf(Client::className(), $client);
         // setting the cient component up in yii will make the client connection available
         // when required to determine the clients dbRemote connection for the Robot model
         $this->setService('client', $client);
         $robot = Robot::findOne(1);
         if ($client->clientCode == 'CLIENT1') {
             $this->assertTrue(!$robot->hasAttribute('extraField'));
         } else {
             // the robot table for CLIENT2s dbRemote connection has an extra extraField attribute
             $this->assertTrue($robot->hasAttribute('extraField'));
         }
         // remove all resources other than core db (typical action taken when switching from one client to another)
         $this->assertTrue($dbFactory->removeAllResources());
         $this->assertEquals(1, $dbFactory->getResourceCount());
     }
     $this->assertTrue($dbFactory->removeAllResources(true));
     $this->assertEquals(0, $dbFactory->getResourceCount());
 }
 /**
  * Test active record extensions fullDelete() on partial relation to check warnings
  * across the two test clients
  */
 function testActiveRecordFullDeleteOnPartialRelation()
 {
     $dbFactory = \Yii::$app->get('dbFactory');
     $this->assertEquals(0, $dbFactory->getResourceCount());
     $clients = Client::find()->orderBy('id')->all();
     $this->assertEquals(1, $dbFactory->getResourceCount());
     $cnt = 0;
     foreach ($clients as $client) {
         $this->assertInstanceOf(Client::className(), $client);
         $this->setService('client', $client);
         $this->checkBaseCounts();
         $customerId = $this->createTestCustomerAndOrder($client->clientCode);
         $this->checkBaseCounts('full', $client->clientCode);
         $this->assertTrue($customerId !== false && $customerId > 0);
         $customer = Customer::findOne($customerId);
         $this->assertInstanceOf(Customer::className(), $customer);
         // should be able to do a full delete which will exclude any relations that have
         // been defined as read only
         $this->assertTrue($customer->address->deleteFull());
         $this->checkBaseCounts('lessaddress', $client->clientCode);
         $this->assertTrue($dbFactory->removeAllResources());
         $this->assertEquals(1, $dbFactory->getResourceCount());
     }
     $this->assertTrue($dbFactory->removeAllResources(true));
     $this->assertEquals(0, $dbFactory->getResourceCount());
 }