Inheritance: extends PHPUnit_Framework_TestCase
Exemplo n.º 1
0
	/**
	 * Creates and instance of the mock JApplication object.
	 *
	 * @param   TestCase  $test  A test object.
	 * @param   array     $data  Data to prime the cache with.
	 *
	 * @return  object
	 *
	 * @since   12.1
	 */
	public static function create(TestCase $test, $data = array())
	{
		self::$cache = $data;

		// Collect all the relevant methods in JConfig.
		$methods = array(
			'get',
			'store',
		);

		// Create the mock.
		$mockObject = $test->getMock(
			'JCache',
			$methods,
			// Constructor arguments.
			array(),
			// Mock class name.
			'',
			// Call original constructor.
			false
		);

		$test->assignMockCallbacks(
			$mockObject,
			array(
				'get' => array(get_called_class(), 'mockGet'),
				'store' => array(get_called_class(), 'mockStore'),
			)
		);

		return $mockObject;
	}
Exemplo n.º 2
0
 public function testAll()
 {
     $obj = new \PHPCraftdream\TestCase\TestCaseClassForTest();
     $testCase = new TestCase();
     $rand1 = bin2hex(random_bytes(5));
     $rand2 = bin2hex(random_bytes(5));
     $obj->setProtected($rand1);
     $this->assertEquals($rand1, $obj->getProtected());
     $obj->setPrivate($rand2);
     $this->assertEquals($rand2, $obj->getPrivate());
     //-------------------------------------------------------
     $rand3 = bin2hex(random_bytes(5));
     $rand4 = bin2hex(random_bytes(5));
     $testCase->setProp($obj, 'propertyProtected', $rand3);
     $this->assertEquals($rand3, $obj->getProtected());
     $testCase->setProp($obj, 'propertyPrvate', $rand4);
     $this->assertEquals($rand4, $obj->getPrivate());
     //-------------------------------------------------------
     $rand5 = bin2hex(random_bytes(5));
     $rand6 = bin2hex(random_bytes(5));
     $obj->setProtected($rand5);
     $this->assertEquals($rand5, $testCase->getProp($obj, 'propertyProtected'));
     $obj->setPrivate($rand6);
     $this->assertEquals($rand6, $testCase->getProp($obj, 'propertyPrvate'));
     //-------------------------------------------------------
 }
Exemplo n.º 3
0
 /**
  * Creates and instance of the mock WebServiceApplicationWeb object.
  *
  * The test can implement the following overrides:
  * - mockAppendBody
  * - mockGetBody
  * - mockPrepentBody
  * - mockSetBody
  *
  * If any *Body methods are implemented in the test class, all should be implemented otherwise behaviour will be unreliable.
  *
  * @param   TestCase  $test     A test object.
  * @param   array     $options  A set of options to configure the mock.
  *
  * @return  PHPUnit_Framework_MockObject_MockObject
  *
  * @since   11.3
  */
 public static function create($test, $options = array())
 {
     // Set expected server variables.
     if (!isset($_SERVER['HTTP_HOST'])) {
         $_SERVER['HTTP_HOST'] = 'localhost';
     }
     // Collect all the relevant methods in WebServiceApplicationWeb (work in progress).
     $methods = array('allowCache', 'appendBody', 'clearHeaders', 'close', 'execute', 'get', 'getBody', 'getDocument', 'getHeaders', 'getIdentity', 'getLanguage', 'getSession', 'loadConfiguration', 'loadDispatcher', 'loadDocument', 'loadIdentity', 'loadLanguage', 'loadSession', 'prependBody', 'redirect', 'registerEvent', 'sendHeaders', 'set', 'setBody', 'setHeader', 'triggerEvent');
     // Create the mock.
     $mockObject = $test->getMock('WebServiceApplicationWeb', $methods, array(), '', true);
     // Mock calls to JApplicationWeb::getDocument().
     $mockObject->expects($test->any())->method('getDocument')->will($test->returnValue(TestMockDocument::create($test)));
     // Mock calls to JApplicationWeb::getLanguage().
     $mockObject->expects($test->any())->method('getLanguage')->will($test->returnValue(TestMockLanguage::create($test)));
     // Mock a call to JApplicationWeb::getSession().
     if (isset($options['session'])) {
         $mockObject->expects($test->any())->method('getSession')->will($test->returnValue($options['session']));
     } else {
         $mockObject->expects($test->any())->method('getSession')->will($test->returnValue(TestMockSession::create($test)));
     }
     $test->assignMockCallbacks($mockObject, array('appendBody' => array(is_callable(array($test, 'mockAppendBody')) ? $test : get_called_class(), 'mockAppendBody'), 'getBody' => array(is_callable(array($test, 'mockGetBody')) ? $test : get_called_class(), 'mockGetBody'), 'prependBody' => array(is_callable(array($test, 'mockPrependBody')) ? $test : get_called_class(), 'mockPrependBody'), 'setBody' => array(is_callable(array($test, 'mockSetBody')) ? $test : get_called_class(), 'mockSetBody')));
     // Reset the body storage.
     self::$body = array();
     return $mockObject;
 }
Exemplo n.º 4
0
	/**
	 * Creates and instance of the mock JApplicationCli object.
	 *
	 * @param   TestCase  $test     A test object.
	 * @param   array     $options  A set of options to configure the mock.
	 *
	 * @return  PHPUnit_Framework_MockObject_MockObject
	 *
	 * @since   12.2
	 */
	public static function create($test, $options = array())
	{
		// Collect all the relevant methods in JApplicationCli.
		$methods = array(
			'get',
			'execute',
			'loadConfiguration',
			'out',
			'in',
			'set',
		);

		// Create the mock.
		$mockObject = $test->getMock(
			'JApplicationCli',
			$methods,
			// Constructor arguments.
			array(),
			// Mock class name.
			'',
			// Call original constructor.
			true
		);

		return $mockObject;
	}
Exemplo n.º 5
0
 /**
  * Tests PhpUnitTest\TestCase::getReflectionProperty
  */
 public function testGetReflectionProperty()
 {
     $sut = new TestCase();
     $testSubject = new TestingClass();
     $result = $sut->getReflectionProperty($testSubject, 'property');
     $this->assertInstanceOf('\\ReflectionProperty', $result);
 }
Exemplo n.º 6
0
 /**
  * @param string $methodName
  * @param bool $moreThanOnce
  */
 public function addRequiredMethod($methodName, $moreThanOnce = false)
 {
     if ($moreThanOnce) {
         $this->mock->expects($this->testCase->atLeastOnce())->method($methodName)->with();
     } else {
         $this->mock->expects($this->testCase->once())->method($methodName)->with();
     }
 }
Exemplo n.º 7
0
 /**
  * Creates and instance of the mock JApplicationCli object.
  *
  * @param   TestCase  $test     A test object.
  * @param   array     $options  A set of options to configure the mock.
  *
  * @return  PHPUnit_Framework_MockObject_MockObject
  *
  * @since   12.2
  */
 public static function create($test, $options = array())
 {
     // Collect all the relevant methods in JApplicationCli.
     $methods = array('get', 'execute', 'loadConfiguration', 'out', 'in', 'set');
     // Create the mock.
     $mockObject = $test->getMock('JApplicationCli', $methods, array(), '', true);
     return $mockObject;
 }
Exemplo n.º 8
0
 /**
  * Check if the test object should be filtered out.
  *
  * @param TestSuite|TestCase $test
  * @return bool
  */
 protected function matched($test)
 {
     foreach ($this->groups as $group) {
         if ($test->in_group($group)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Creates and instance of the mock JApplicationCli object.
  *
  * @param   TestCase  $test     A test object.
  * @param   array     $options  A set of options to configure the mock.
  *
  * @return  PHPUnit_Framework_MockObject_MockObject
  *
  * @since   12.2
  */
 public static function create($test, $options = array())
 {
     // Collect all the relevant methods in JApplicationCli.
     $methods = self::getMethods();
     // Create the mock.
     $mockObject = $test->getMock('JApplicationCli', $methods, array(), '', true);
     $mockObject = self::addBehaviours($test, $mockObject, $options);
     return $mockObject;
 }
 /**
  * Creates and instance of the mock JApplication object.
  *
  * @param   TestCase  $test  A test object.
  * @param   array     $data  Data to prime the cache with.
  *
  * @return  object
  *
  * @since   12.1
  */
 public static function create(TestCase $test, $data = array())
 {
     self::$cache = $data;
     // Collect all the relevant methods in JConfig.
     $methods = array('get', 'store');
     // Create the mock.
     $mockObject = $test->getMock('JCache', $methods, array(), '', false);
     $test->assignMockCallbacks($mockObject, array('get' => array(get_called_class(), 'mockGet'), 'store' => array(get_called_class(), 'mockStore')));
     return $mockObject;
 }
Exemplo n.º 11
0
 /**
  * Returns the outcome of a specific test
  *
  * @param   unittest.TestCase test
  * @return  unittest.TestOutcome
  */
 public function outcomeOf(TestCase $test)
 {
     $key = $test->hashCode();
     foreach ([$this->succeeded, $this->failed, $this->skipped] as $lookup) {
         if (isset($lookup[$key])) {
             return $lookup[$key];
         }
     }
     return null;
 }
Exemplo n.º 12
0
 /**
  * Creates and instance of the mock JApplicationCms object.
  *
  * The test can implement the following overrides:
  * - mockAppendBody
  * - mockGetBody
  * - mockPrepentBody
  * - mockSetBody
  *
  * If any *Body methods are implemented in the test class, all should be implemented otherwise behaviour will be unreliable.
  *
  * @param   TestCase  $test     A test object.
  * @param   array     $options  A set of options to configure the mock.
  *
  * @return  PHPUnit_Framework_MockObject_MockObject
  *
  * @since   3.2
  */
 public static function create($test, $options = array())
 {
     // Set expected server variables.
     if (!isset($_SERVER['HTTP_HOST'])) {
         $_SERVER['HTTP_HOST'] = 'localhost';
     }
     $methods = self::getMethods();
     // Create the mock.
     $mockObject = $test->getMock('JApplicationCms', $methods, array(), '', true);
     $mockObject = self::addBehaviours($test, $mockObject, $options);
     return $mockObject;
 }
 /**
  * Add testcases to the provided TestSuite from the XML node
  *
  * @param TestSuite         $testSuite
  * @param \SimpleXMLElement $xml
  */
 public function addTestCase(TestSuite $testSuite, \SimpleXMLElement $xml)
 {
     foreach ($xml->xpath('./testcase') as $element) {
         $testcase = new TestCase((string) $element['name'], (int) $element['assertions'], (double) $element['time'], (string) $element['class'], (string) $element['file'], (int) $element['line']);
         if ($element->error) {
             $testcase->setError(new TestError((string) $element->error[0]->attributes()->type, (string) $element->error[0]));
         }
         if ($element->failure) {
             $testcase->setFailure(new TestFailure((string) $element->failure[0]->attributes()->type, (string) $element->failure[0]));
         }
         $testSuite->addTestCase($testcase);
     }
 }
Exemplo n.º 14
0
 /**
  * Set up test env
  *
  * @return void
  * @author Dan Cox
  */
 public function setUp()
 {
     parent::setUp();
     $this->app->add(new ProjectCreate());
     $this->command = $this->app->find('project:create');
     $this->config = m::mock('config');
 }
Exemplo n.º 15
0
 /**
  * Delete the keys that were added to the database during the test
  */
 public function tearDown()
 {
     parent::tearDown();
     Redis::del($this->testingResource->testModelHashId);
     Redis::del($this->testingResource->testModelSearchableId);
     Redis::del("testmodels");
 }
Exemplo n.º 16
0
 /**
  * Called before each test.
  */
 public function setUp()
 {
     parent::setUp();
     $this->user = factory(\App\User::class)->create();
     $this->client = factory(\App\Client::class)->create(['user_id' => $this->user->id]);
     $this->bill = factory(\App\Bill::class)->create(['user_id' => $this->user->id, 'client_id' => $this->client->id, 'paid' => 1]);
 }
 public function setup()
 {
     parent::setup();
     Session::start();
     $this->app["request"]->setSession(Session::driver());
     FieldPresenter::presenter(null);
 }
Exemplo n.º 18
0
 public function setUp()
 {
     parent::setUp();
     Artisan::call('migrate');
     Artisan::call('db:seed');
     Session::start();
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  * @return void
  */
 protected function setUp()
 {
     parent::setUp();
     $this->options = new JRegistry();
     $this->uri = new JUri();
     $this->object = new JGoogleEmbedAnalytics($this->options, $this->uri);
 }
Exemplo n.º 20
0
 public function setup()
 {
     parent::setup();
     $todo = factory(\App\Todo::class)->create();
     // echo $todo;
     $this->id = $todo['id'];
 }
 /**
  * Sets up the fixture.
  *
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     parent::setUp();
     $this->dbo = $this->getMockDatabase();
     // Mock the escape method to ensure the API is calling the DBO's escape method.
     $this->assignMockCallbacks($this->dbo, array('escape' => array($this, 'getMockEscape')));
 }
Exemplo n.º 22
0
 /**
  * Called first.
  */
 public function setUp()
 {
     parent::setUp();
     $this->admin = factory(App\User::class, 'admin')->create();
     $this->user = factory(App\User::class)->create();
     $this->client = factory(App\Client::class)->create(['user_id' => $this->user->id]);
 }
	/**
	 * Sets up dependencies for the test.
	 *
	 * @return  void
	 *
	 * @since   12.1
	 */
	protected function setUp()
	{
		parent::setUp();

		require_once JPATH_PLATFORM . '/joomla/form/fields/url.php';
		include_once dirname(__DIR__) . '/inspectors.php';
	}
Exemplo n.º 24
0
 public function setUp()
 {
     parent::setUp();
     $this->published_motion = factory(App\Motion::class, 'published')->create();
     $this->signIn();
     $this->user->addUserRoleByName('councillor');
 }
Exemplo n.º 25
0
 public function setUp()
 {
     parent::setUp();
     // Don't forget this!
     $this->faker = Faker\Factory::create();
     //$this->prepareForTests();
 }
Exemplo n.º 26
0
 public function setUp()
 {
     parent::setUp();
     $this->withoutMiddleware();
     $this->withoutEvents();
     factory(\Yab\Quarx\Models\Page::class)->create();
 }
Exemplo n.º 27
0
 /**
  * Initial setup function for tests
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Artisan::call('migrate');
     Artisan::call('db:seed');
     $this->setVariables();
 }
Exemplo n.º 28
0
 /**
  * Setup the test environment.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     // Use an in-memory DB
     $this->app['config']->set('database.default', 'csvSeederTest');
     $this->app['config']->set('database.connections.csvSeederTest', ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']);
 }
Exemplo n.º 29
0
 /**
  * Overrides the parent tearDown method.
  *
  * @return  void
  *
  * @see     PHPUnit_Framework_TestCase::tearDown()
  * @since   11.1
  */
 protected function tearDown()
 {
     $this->restoreFactoryState();
     // Reset the dispatcher instance.
     TestReflection::setValue('JPluginHelper', 'plugins', null);
     parent::tearDown();
 }
Exemplo n.º 30
0
 function setUp()
 {
     parent::setUp();
     $this->messenger = new Messenger('random_access_token');
     $this->message = new Message('Some title');
     $this->recipient = 123456789;
 }