1. Go to this page and download the library: Download cosma/phest library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cosma / phest example snippets
# /path/to/phalcon/project/tests/bootstrap.php
/**
* Define TEST_PATH to point to path/to/phalcon/project/tests/
*/
define('TEST_PATH', __DIR__ );
/**
* Require Phest environment.php file
*/
library bootstrap.php file
*/
# /path/to/phalcon/project/tests/config.php
return new \Phalcon\Config([
'someConfigVariable' => 'some value',
]);
use Cosma\Phest\TestCase\UnitTestCase;
class SomeVerySimpleUnitTest extends UnitTestCase
{
public function testSomething()
{
$additionClass = new AdditionCLass();
$this->assertEquals(3, $additionClass->calculate(1, 2));
}
}
use Cosma\Phest\TestCase\WebTestCase;
class SomeWebFunctionalTest extends WebTestCase
{
public function setUp()
{
/**
* Required call
*/
parent::setUp();
$db = $this->getMockBuilder('Phalcon\Db\Adapter\Pdo\Mysql')
->disableOriginalConstructor()
->setMethods(['query'])
->getMock();
$this->mockService('db', $db);
}
public function testSomething()
{
/** @var \Phalcon\Http\Response $response */
$response = $this->sendRequest(
'/test_endpoint', 'POST', ['test_var' => 'value'], ['Header1' => 223456789, 'Header2' => 'value2']);
$this->assertInstanceOf('Phalcon\Http\Response', $response);
$this->assertEquals('200 OK', $response->getStatusCode());
$this->assertEquals('value', $response->getContent());
}
public function testGetHealthCheck()
{
/** @var \Phalcon\Http\Response $response */
$response = $this->sendRequest(
'/healthCheck', 'GET', [], []);
$this->assertInstanceOf('Phalcon\Http\Response', $response);
$this->assertEquals('200 OK', $response->getStatusCode());
}
}
use Cosma\Phest\TestCase\UnitTestCase;
/**
* Will retry 10 times all the Class tests that are failing
*
* @retry 10
*/
class SomeVerySimpleUnitTest extends UnitTestCase
{
/**
* Will retry 10 times this test if is failing because of the class annotation from above
*/
public function testFirst()
{
// ...
}
/**
* Will retry 4 times this test if is failing because of the method annotation from below
*
* @retry 4
*/
public function testSecond()
{
// ...
}
}
use Cosma\Phest\TestCase\UnitTestCase;
class SomeUnitTest extends UnitTestCase
{
public function testGetsAverageTemperatureFromThreeServiceReadings()
{
$service = \Mockery::mock('service');
$service->shouldReceive('readTemp')->times(3)->andReturn(10, 12, 14);
$temperature = new Temperature($service);
$this->assertEquals(12, $temperature->average());
}
}
bash
$ php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.