setUpResourceFactoryMock( Mockery::mock()->shouldReceive('inspect')->andReturn(self::createInspector(false))->getMock() ); // Passing array(null) is required to make Mockery call the constructor... $form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); $form->setTokenDisabled(); $this->assertTrue( LdapResourceForm::isValidResource($form->create()), 'ResourceForm claims that a valid ldap resource is not valid' ); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testInvalidLdapResourceIsNotValid() { $this->setUpResourceFactoryMock( Mockery::mock()->shouldReceive('inspect')->andReturn(self::createInspector(true))->getMock() ); // Passing array(null) is required to make Mockery call the constructor... $form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); $form->setTokenDisabled(); $this->assertFalse( LdapResourceForm::isValidResource($form->create()), 'ResourceForm claims that an invalid ldap resource is valid' ); } protected function setUpResourceFactoryMock($resourceMock) { Mockery::mock('alias:Icinga\Data\ResourceFactory') ->shouldReceive('createResource') ->with(Mockery::type('Icinga\Data\ConfigObject')) ->andReturn($resourceMock); } public static function createInspector($error = false, $log = array('log')) { if (! $error) { $calls = array( 'hasError' => false, 'toArray' => $log ); } else { $calls = array( 'hasError' => true, 'getError' => 'Error', 'toArray' => $log ); } return Mockery::mock('Icinga\Data\Inspection', $calls); } }