1. Go to this page and download the library: Download rafael.moran/uitest 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/ */
rafael.moran / uitest example snippets
// file: run-tests.php (you can pick whatever filename you want)
Load();
// Entities to test
hp';
// Use case
$tester = new \RafaelMoran\UITest\UITester(['verbose' => true]); // set to false to not display details
// Run all tests
$tester->all();
use RafaelMoran\UITest\UITester;
// Use case
$tester = new UITester(); // It runs all test from $_ENV['PATH_TESTS'], results are not displayed.
// Or
// It's run all tests from `/another/real/weird/path/`
$tester = new UITester([
"path" => "/another/real/weird/path/",
"verbose" => true,
// Or...
"v" => true,
]);
/*
* It runs all test cases from the default test folder `/tests/`
* and display in detail all assertions statuses.
*/
$tester->all();
// ...
/**
* It runs all test cases from the default test folder `/another/test/folder/`
* and display in detail all assertions statuses.
*/
$tester->all("/another/test/folder/");
/**
* It runs only `CarTest_518135355` from the default test folder `/tests/`
* and display in detail all assertions statuses.
*/
$tester->only('CarTest_518135355')
->outputTestResults();
// ...
/**
* It runs only `CarTest_518135355` and `GetRandomStrTest_1218383454` test cases
* from the default test folder `/tests/` and display in detail
* all assertions statuses.
*/
$tester->only([
'CarTest_518135355',
'GetRandomStrTest_1218383454'
])
->outputTestResults();
// ...
/**
* It runs only `CarTest_518135355` from the default test folder
* `/another/real/weird/path/` and display in detail all assertions statuses.
*/
$tester->setPath('/another/real/weird/path/')
->only('CarTest_518135355')
->outputTestResults();
namespace <YourAppName>\UITesting\Tests;
use RafaelMoran\UITest\UITestCase;
// New test case needs to extend from abstract class UITestCase.
class CarTestCase extends UITestCase
{
/**
* Tests if (new Car)->getType() returns a non-empty string.
*
* @return void
*/
public function test_cartype_is_string_and_not_empty() : void
{
$car_type = (new Car)->getType();
$this->assertNotEmpty($car_type)
->assertIsString($car_type);
}
/**
* Tests if values are float type.
*
* @return void
*/
public function test_if_value_is_float() : void
{
$this->assertIsFloat(27.25);
$this->assertIsFloat('abc');
$this->assertIsFloat(23);
$this->assertIsFloat(23.5);
$this->assertIsFloat(1e7); // Scientific Notation. This is true.
$this->assertIsFloat(true);
}
}
namespace <YourAppName>\UITesting\Tests;
use RafaelMoran\UITest\UITestCase;
class ClassNameXTestCase_518135355 extends UITestCase
{
/**
* Tests if 'ClassNameXTestCase_518135355'...
*
* All tests MUST START WITH "test_".
*
* @return void
*/
public function test_() : void
{
/**
* Read ./lib/UITestCase.php file regarding assertions.
*
* Examples:
*
* $this->assertLength( 'abc', 3 ); # true
* $this->assertArrayHasKey('key3', array('key3'=>null, 'key4'=>1)); # true
*/
}
}
namespace <YourAppName>\UITesting\Tests;
use RafaelMoran\UITest\UITestCase;
class FunctionNameXTestCase_518135355 extends UITestCase
{
/**
* Tests if 'FunctionNameXTestCase_518135355'...
*
* All tests MUST START WITH "test_".
*
* @return void
*/
public function test_() : void
{
/**
* Read ./lib/UITestCase.php file regarding assertions.
*
* Examples:
*
* $this->assertLength( 'abc', 3 ); # true
* $this->assertArrayHasKey('key3', array('key3'=>null, 'key4'=>1)); # true
*/
}
}
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
// Examples
rPlane.php';
// Use case
$tester = new \RafaelMoran\UITest\UITester(['verbose' => true]); // set to false to not display details
// Run all tests
$tester->all();
// Use case
$tester = new UITester(['verbose' => true]); // It displays all assertions in detail
// Or...
$tester = new UITester(['v' => true]); // It displays all assertions in detail
// ...
// Run all tests
$tester->all();
//...
// Only specific tests (string)
$tester->only('CarTest_518135355')
->outputTestResults();
// ...
// Only specific tests (array)
$tester->only([
'CarTest_518135355',
'GetRandomStrTest_1218383454'
])
->outputTestResults();