public function testdeleteGroup_groupHasClients() { $clientModel = new \Model_Client(); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('findOne')->will($this->returnValue($clientModel)); $di = new \Box_Di(); $di['db'] = $dbMock; $service = new \Box\Mod\Client\Service(); $service->setDi($di); $model = new \Model_ClientGroup(); $model->loadBean(new \RedBeanPHP\OODBBean()); $this->setExpectedException('\\Box_Exception', 'Can not remove group with clients'); $service->deleteGroup($model); }