First Commit
This commit is contained in:
commit
44cc86c51a
13 changed files with 3992 additions and 0 deletions
88
.gitignore
vendored
Normal file
88
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
|
||||
# Created by https://www.gitignore.io/api/vim,macos,linux,windows,composer
|
||||
|
||||
### Composer ###
|
||||
composer.phar
|
||||
/vendor/
|
||||
|
||||
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
|
||||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
||||
# composer.lock
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
*.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Vim ###
|
||||
# swap
|
||||
[._]*.s[a-v][a-z]
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-v][a-z]
|
||||
[._]sw[a-p]
|
||||
# session
|
||||
Session.vim
|
||||
# temporary
|
||||
.netrwhist
|
||||
# auto-generated tag files
|
||||
tags
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.gitignore.io/api/vim,macos,linux,windows,composer
|
||||
10
codeception.yml
Normal file
10
codeception.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
paths:
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
envs: tests/_envs
|
||||
actor_suffix: Tester
|
||||
extensions:
|
||||
enabled:
|
||||
- Codeception\Extension\RunFailed
|
||||
25
composer.json
Normal file
25
composer.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "adeattwood/yii-helpers",
|
||||
"description": "Helpers for the yii2 framework",
|
||||
"type": "library",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ade Attwood",
|
||||
"email": "attwood16@googlemail.com"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "stable",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"adeattwood\\helpers\\": "src"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"yiisoft/yii2": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"codeception/specify": "^0.4.6",
|
||||
"codeception/verify": "^0.3.3",
|
||||
"codeception/codeception": "^2.3"
|
||||
}
|
||||
}
|
||||
3044
composer.lock
generated
Normal file
3044
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
109
src/ArrayObject.php
Normal file
109
src/ArrayObject.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace adeattwood\helpers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Html;
|
||||
use adeattwood\helpers\Enum;
|
||||
|
||||
class ArrayObject extends \ArrayObject
|
||||
{
|
||||
public function __construct( $array = [], $flags = null, $iterator_class = 'ArrayIterator' )
|
||||
{
|
||||
if( $flags === null ) {
|
||||
$flags = self::ARRAY_AS_PROPS;
|
||||
}
|
||||
|
||||
parent::__construct( $array, $flags, $iterator_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function contains( $item )
|
||||
{
|
||||
$flipped = array_flip( ( array )$this );
|
||||
return isset( $flipped[ $item ] );
|
||||
}
|
||||
|
||||
public function toTable(
|
||||
$transpose = false,
|
||||
$recursive = false,
|
||||
$typeHint = true,
|
||||
$tableOptions = ['class' => 'table table-bordered table-striped'],
|
||||
$keyOptions = [],
|
||||
$valueOptions = ['style' => 'cursor: default; border-bottom: 1px #aaa dashed;'],
|
||||
$null = '<span class="not-set">(not set)</span>'
|
||||
) {
|
||||
|
||||
// Sanity check
|
||||
if (empty( ( array )$this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$array = ( array )$this;
|
||||
|
||||
// Start the table
|
||||
$table = Html::beginTag('table', $tableOptions) . "\n";
|
||||
// The header
|
||||
$table .= "\t<tr>";
|
||||
if ($transpose) {
|
||||
foreach ($this as $key => $value) {
|
||||
if ($typeHint) {
|
||||
$valueOptions['title'] = Enum::getType(strtoupper($value));
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$value = '<pre>' . print_r($value, true) . '</pre>';
|
||||
} else {
|
||||
$value = Html::tag('span', $value, $valueOptions);
|
||||
}
|
||||
$table .= "\t\t<th>" . Html::tag('span', $key, $keyOptions) . "</th>" .
|
||||
"<td>" . $value . "</td>\n\t</tr>\n";
|
||||
}
|
||||
$table .= "</table>";
|
||||
return $table;
|
||||
}
|
||||
if (!isset($array[0]) || !is_array($array[0])) {
|
||||
$array = array($array);
|
||||
}
|
||||
// Take the keys from the first row as the headings
|
||||
foreach (array_keys($array[0]) as $heading) {
|
||||
$table .= '<th>' . Html::tag('span', $heading, $keyOptions) . '</th>';
|
||||
}
|
||||
$table .= "</tr>\n";
|
||||
// The body
|
||||
foreach ($array as $row) {
|
||||
$table .= "\t<tr>";
|
||||
foreach ($row as $cell) {
|
||||
$table .= '<td>';
|
||||
// Cast objects
|
||||
if (is_object($cell)) {
|
||||
$cell = (array)$cell;
|
||||
}
|
||||
if ($recursive === true && is_array($cell) && !empty($cell)) {
|
||||
// Recursive mode
|
||||
$table .= "\n" . static::array2table($cell, true, true) . "\n";
|
||||
} else {
|
||||
if (!is_null($cell) && is_bool($cell)) {
|
||||
$val = $cell ? 'true' : 'false';
|
||||
$type = 'boolean';
|
||||
} else {
|
||||
$chk = (strlen($cell) > 0);
|
||||
$type = $chk ? Enum::getType($cell) : 'null';
|
||||
$val = $chk ? htmlspecialchars((string)$cell) : $null;
|
||||
}
|
||||
if ($typeHint) {
|
||||
$valueOptions['title'] = $type;
|
||||
}
|
||||
$table .= Html::tag('span', $val, $valueOptions);
|
||||
}
|
||||
$table .= '</td>';
|
||||
}
|
||||
$table .= "</tr>\n";
|
||||
}
|
||||
$table .= '</table>';
|
||||
return $table;
|
||||
}
|
||||
}
|
||||
115
src/Enum.php
Normal file
115
src/Enum.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace adeattwood\helpers;
|
||||
|
||||
/**
|
||||
* Class Enum
|
||||
* @author Ade Attwood
|
||||
*/
|
||||
class Enum extends \yii\base\Object
|
||||
{
|
||||
const TYPE_ARRAY = 'array';
|
||||
const TYPE_NULL = 'null';
|
||||
const TYPE_BOOL = 'boolean';
|
||||
const TYPE_FLOAT = 'float';
|
||||
const TYPE_INT = 'integer';
|
||||
const TYPE_DATETIME = 'datetime';
|
||||
const TYPE_STRING = 'string';
|
||||
const TYPE_RESOURCE = 'resource';
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses and returns a variable type
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ~~~php
|
||||
* $data = [
|
||||
* 'id' => 1,
|
||||
* 'name' => 'Smith',
|
||||
* 'date' => '2014/01/22',
|
||||
* 'amount' => '4,323.23',
|
||||
* 'relations' => ['spouse', 'children']
|
||||
* ];
|
||||
* foreach ($data as $k=>$v) {
|
||||
* echo "<b>$k</b>: " . Enum::getType($v) . "<br>";
|
||||
* }
|
||||
* ~~~
|
||||
*
|
||||
* @param string $var the variable to be parsed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getType( $var )
|
||||
{
|
||||
if (is_array($var)) {
|
||||
return static::TYPE_ARRAY;
|
||||
} elseif (is_object($var)) {
|
||||
return "object";
|
||||
//return $var::className();
|
||||
} elseif (is_resource($var)) {
|
||||
return 'resource';
|
||||
} elseif (is_null($var)) {
|
||||
return static::TYPE_NULL;
|
||||
} elseif (is_bool($var)) {
|
||||
return static::TYPE_BOOL;
|
||||
} elseif (is_float($var) || (is_numeric(str_replace(',', '', $var)) && strpos($var, '.') > 0 &&
|
||||
is_float((float)str_replace(',', '', $var)))
|
||||
) {
|
||||
return static::TYPE_FLOAT;
|
||||
} elseif (is_int($var) || (is_numeric($var) && is_int((int)$var))) {
|
||||
return static::TYPE_INT;
|
||||
} elseif (is_scalar($var) && strtotime($var) !== false) {
|
||||
return static::TYPE_DATETIME;
|
||||
} elseif (is_scalar($var)) {
|
||||
return static::TYPE_STRING;
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a variable is empty or not set.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ~~~
|
||||
* if (Enum::isEmpty([]) {
|
||||
* echo 'Not empty';
|
||||
* }
|
||||
* ~~~
|
||||
*
|
||||
* @param mixed $var variable to perform the check
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isEmpty($var)
|
||||
{
|
||||
return !isset($var) ? true : (is_array($var) ? empty($var) : ($var === null || $var === ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format and convert "bytes" to its optimal higher metric unit.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ~~~
|
||||
* echo Enum::formatBytes(120.32); // returns: 1.17 KB
|
||||
* echo Enum::formatBytes(28434322.25); // returns: 27.12 MB
|
||||
* echo Enum::formatBytes(17328347842.25, 3); // returns: 16.138 GB
|
||||
* ~~~
|
||||
*
|
||||
* @param double $bytes number of bytes
|
||||
* @param integer $precision the number of decimal places to round off
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function formatBytes($bytes, $precision = 2)
|
||||
{
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$bytes = max($bytes, 0);
|
||||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
||||
$pow = min($pow, count($units) - 1);
|
||||
$bytes /= pow(1024, $pow);
|
||||
return round($bytes, $precision) . ' ' . $units[$pow];
|
||||
}
|
||||
}
|
||||
0
tests/_data/.gitkeep
Normal file
0
tests/_data/.gitkeep
Normal file
0
tests/_output/.gitkeep
Normal file
0
tests/_output/.gitkeep
Normal file
10
tests/_support/Helper/Unit.php
Normal file
10
tests/_support/Helper/Unit.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
namespace Helper;
|
||||
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
|
||||
class Unit extends \Codeception\Module
|
||||
{
|
||||
|
||||
}
|
||||
26
tests/_support/UnitTester.php
Normal file
26
tests/_support/UnitTester.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\UnitTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
||||
502
tests/_support/_generated/UnitTesterActions.php
Normal file
502
tests/_support/_generated/UnitTesterActions.php
Normal file
|
|
@ -0,0 +1,502 @@
|
|||
<?php //[STAMP] f70ebbe2fe34ed5c20c33b65fb3a7753
|
||||
namespace _generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
// You should not change it manually as it will be overwritten on next build
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
use Codeception\Module\Asserts;
|
||||
use Helper\Unit;
|
||||
|
||||
trait UnitTesterActions
|
||||
{
|
||||
/**
|
||||
* @return \Codeception\Scenario
|
||||
*/
|
||||
abstract protected function getScenario();
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are equal. If you're comparing floating-point values,
|
||||
* you can specify the optional "delta" parameter which dictates how great of a precision
|
||||
* error are you willing to tolerate in order to consider the two values equal.
|
||||
*
|
||||
* Regular example:
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->assertEquals($element->getChildrenCount(), 5);
|
||||
* ```
|
||||
*
|
||||
* Floating-point example:
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->assertEquals($calculator->add(0.1, 0.2), 0.3, 'Calculator should add the two numbers correctly.', 0.01);
|
||||
* ```
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @param float $delta
|
||||
* @see \Codeception\Module\Asserts::assertEquals()
|
||||
*/
|
||||
public function assertEquals($expected, $actual, $message = null, $delta = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are not equal. If you're comparing floating-point values,
|
||||
* you can specify the optional "delta" parameter which dictates how great of a precision
|
||||
* error are you willing to tolerate in order to consider the two values not equal.
|
||||
*
|
||||
* Regular example:
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->assertNotEquals($element->getChildrenCount(), 0);
|
||||
* ```
|
||||
*
|
||||
* Floating-point example:
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->assertNotEquals($calculator->add(0.1, 0.2), 0.4, 'Calculator should add the two numbers correctly.', 0.01);
|
||||
* ```
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @param float $delta
|
||||
* @see \Codeception\Module\Asserts::assertNotEquals()
|
||||
*/
|
||||
public function assertNotEquals($expected, $actual, $message = null, $delta = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are same
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertSame()
|
||||
*/
|
||||
public function assertSame($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are not same
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotSame()
|
||||
*/
|
||||
public function assertNotSame($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that actual is greater than expected
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertGreaterThan()
|
||||
*/
|
||||
public function assertGreaterThan($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that actual is greater or equal than expected
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertGreaterThanOrEqual()
|
||||
*/
|
||||
public function assertGreaterThanOrEqual($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that actual is less than expected
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertLessThan()
|
||||
*/
|
||||
public function assertLessThan($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that actual is less or equal than expected
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertLessThanOrEqual()
|
||||
*/
|
||||
public function assertLessThanOrEqual($expected, $actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that haystack contains needle
|
||||
*
|
||||
* @param $needle
|
||||
* @param $haystack
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertContains()
|
||||
*/
|
||||
public function assertContains($needle, $haystack, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that haystack doesn't contain needle.
|
||||
*
|
||||
* @param $needle
|
||||
* @param $haystack
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotContains()
|
||||
*/
|
||||
public function assertNotContains($needle, $haystack, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that string match with pattern
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertRegExp()
|
||||
*/
|
||||
public function assertRegExp($pattern, $string, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that string not match with pattern
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotRegExp()
|
||||
*/
|
||||
public function assertNotRegExp($pattern, $string, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that variable is empty.
|
||||
*
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertEmpty()
|
||||
*/
|
||||
public function assertEmpty($actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that variable is not empty.
|
||||
*
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotEmpty()
|
||||
*/
|
||||
public function assertNotEmpty($actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that variable is NULL
|
||||
*
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNull()
|
||||
*/
|
||||
public function assertNull($actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that variable is not NULL
|
||||
*
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertNotNull()
|
||||
*/
|
||||
public function assertNotNull($actual, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that condition is positive.
|
||||
*
|
||||
* @param $condition
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertTrue()
|
||||
*/
|
||||
public function assertTrue($condition, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that condition is negative.
|
||||
*
|
||||
* @param $condition
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertFalse()
|
||||
*/
|
||||
public function assertFalse($condition, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks if file exists
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertFileExists()
|
||||
*/
|
||||
public function assertFileExists($filename, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks if file doesn't exist
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertFileNotExists()
|
||||
*/
|
||||
public function assertFileNotExists($filename, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertGreaterOrEquals()
|
||||
*/
|
||||
public function assertGreaterOrEquals($expected, $actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterOrEquals', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertLessOrEquals()
|
||||
*/
|
||||
public function assertLessOrEquals($expected, $actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessOrEquals', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertIsEmpty()
|
||||
*/
|
||||
public function assertIsEmpty($actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsEmpty', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $key
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertArrayHasKey()
|
||||
*/
|
||||
public function assertArrayHasKey($key, $actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $key
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertArrayNotHasKey()
|
||||
*/
|
||||
public function assertArrayNotHasKey($key, $actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayNotHasKey', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $expectedCount
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertCount()
|
||||
*/
|
||||
public function assertCount($expectedCount, $actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCount', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $class
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertInstanceOf()
|
||||
*/
|
||||
public function assertInstanceOf($class, $actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $class
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertNotInstanceOf()
|
||||
*/
|
||||
public function assertNotInstanceOf($class, $actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotInstanceOf', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* @param $type
|
||||
* @param $actual
|
||||
* @param $description
|
||||
* @see \Codeception\Module\Asserts::assertInternalType()
|
||||
*/
|
||||
public function assertInternalType($type, $actual, $description = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInternalType', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Fails the test with message.
|
||||
*
|
||||
* @param $message
|
||||
* @see \Codeception\Module\Asserts::fail()
|
||||
*/
|
||||
public function fail($message) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Handles and checks exception called inside callback function.
|
||||
* Either exception class name or exception instance should be provided.
|
||||
*
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->expectException(MyException::class, function() {
|
||||
* $this->doSomethingBad();
|
||||
* });
|
||||
*
|
||||
* $I->expectException(new MyException(), function() {
|
||||
* $this->doSomethingBad();
|
||||
* });
|
||||
* ```
|
||||
* If you want to check message or exception code, you can pass them with exception instance:
|
||||
* ```php
|
||||
* <?php
|
||||
* // will check that exception MyException is thrown with "Don't do bad things" message
|
||||
* $I->expectException(new MyException("Don't do bad things"), function() {
|
||||
* $this->doSomethingBad();
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param $exception string or \Exception
|
||||
* @param $callback
|
||||
* @see \Codeception\Module\Asserts::expectException()
|
||||
*/
|
||||
public function expectException($exception, $callback) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('expectException', func_get_args()));
|
||||
}
|
||||
}
|
||||
9
tests/unit.suite.yml
Normal file
9
tests/unit.suite.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Codeception Test Suite Configuration
|
||||
#
|
||||
# Suite for unit or integration tests.
|
||||
|
||||
actor: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Asserts
|
||||
- \Helper\Unit
|
||||
54
tests/unit/ArrayObjectCest.php
Normal file
54
tests/unit/ArrayObjectCest.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
use adeattwood\helpers\ArrayObject;
|
||||
|
||||
|
||||
class ArrayObjectCest
|
||||
{
|
||||
public $arrayObject;
|
||||
|
||||
public $array = [
|
||||
"key_one" => "Value One",
|
||||
"key_two" => "Value Two"
|
||||
];
|
||||
|
||||
public function _before(UnitTester $I)
|
||||
{
|
||||
$this->arrayObject = new ArrayObject( $this->array );
|
||||
}
|
||||
|
||||
public function _after(UnitTester $I)
|
||||
{
|
||||
}
|
||||
|
||||
public function testArrayAsProps(UnitTester $I)
|
||||
{
|
||||
$I->assertEquals( $this->arrayObject->key_one, "Value One" );
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayContains( UnitTester $I )
|
||||
{
|
||||
$I->assertTrue( $this->arrayObject->contains( "Value One" ) );
|
||||
$I->assertFalse( $this->arrayObject->contains( "Not in array" ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testToTable( UnitTester $I )
|
||||
{
|
||||
require __DIR__ . "/../../vendor/yiisoft/yii2/Yii.php";
|
||||
$table = $this->arrayObject->toTable();
|
||||
|
||||
$I->assertContains( '<table class="table table-bordered table-striped">', $table );
|
||||
$I->assertContains( '<span title="string" style="cursor: default; border-bottom: 1px #aaa dashed;">Value One</span>', $table );
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue