Primo Committ
This commit is contained in:
88
vendor/laravel/framework/src/Illuminate/Testing/Assert.php
vendored
Normal file
88
vendor/laravel/framework/src/Illuminate/Testing/Assert.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Testing;
|
||||
|
||||
use ArrayAccess;
|
||||
use Illuminate\Testing\Constraints\ArraySubset;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
use PHPUnit\Framework\Constraint\DirectoryExists;
|
||||
use PHPUnit\Framework\Constraint\FileExists;
|
||||
use PHPUnit\Framework\Constraint\LogicalNot;
|
||||
use PHPUnit\Framework\Constraint\RegularExpression;
|
||||
use PHPUnit\Framework\InvalidArgumentException;
|
||||
use PHPUnit\Util\InvalidArgumentHelper;
|
||||
|
||||
/**
|
||||
* @internal This class is not meant to be used or overwritten outside the framework itself.
|
||||
*/
|
||||
abstract class Assert extends PHPUnit
|
||||
{
|
||||
/**
|
||||
* Asserts that an array has a specified subset.
|
||||
*
|
||||
* @param \ArrayAccess|array $subset
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param bool $checkForIdentity
|
||||
* @param string $msg
|
||||
* @return void
|
||||
*/
|
||||
public static function assertArraySubset($subset, $array, bool $checkForIdentity = false, string $msg = ''): void
|
||||
{
|
||||
if (! (is_array($subset) || $subset instanceof ArrayAccess)) {
|
||||
if (class_exists(InvalidArgumentException::class)) {
|
||||
throw InvalidArgumentException::create(1, 'array or ArrayAccess');
|
||||
} else {
|
||||
throw InvalidArgumentHelper::factory(1, 'array or ArrayAccess');
|
||||
}
|
||||
}
|
||||
|
||||
if (! (is_array($array) || $array instanceof ArrayAccess)) {
|
||||
if (class_exists(InvalidArgumentException::class)) {
|
||||
throw InvalidArgumentException::create(2, 'array or ArrayAccess');
|
||||
} else {
|
||||
throw InvalidArgumentHelper::factory(2, 'array or ArrayAccess');
|
||||
}
|
||||
}
|
||||
|
||||
$constraint = new ArraySubset($subset, $checkForIdentity);
|
||||
|
||||
PHPUnit::assertThat($array, $constraint, $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a file does not exist.
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
public static function assertFileDoesNotExist(string $filename, string $message = ''): void
|
||||
{
|
||||
static::assertThat($filename, new LogicalNot(new FileExists), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a directory does not exist.
|
||||
*
|
||||
* @param string $directory
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void
|
||||
{
|
||||
static::assertThat($directory, new LogicalNot(new DirectoryExists), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a string matches a given regular expression.
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
|
||||
{
|
||||
static::assertThat($string, new RegularExpression($pattern), $message);
|
||||
}
|
||||
}
|
||||
279
vendor/laravel/framework/src/Illuminate/Testing/Constraints/ArraySubset.php
vendored
Normal file
279
vendor/laravel/framework/src/Illuminate/Testing/Constraints/ArraySubset.php
vendored
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Testing\Constraints;
|
||||
|
||||
use ArrayObject;
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use PHPUnit\Runner\Version;
|
||||
use SebastianBergmann\Comparator\ComparisonFailure;
|
||||
use Traversable;
|
||||
|
||||
if (class_exists(Version::class) && (int) Version::series()[0] >= 9) {
|
||||
/**
|
||||
* @internal This class is not meant to be used or overwritten outside the framework itself.
|
||||
*/
|
||||
final class ArraySubset extends Constraint
|
||||
{
|
||||
/**
|
||||
* @var iterable
|
||||
*/
|
||||
private $subset;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $strict;
|
||||
|
||||
/**
|
||||
* Create a new array subset constraint instance.
|
||||
*
|
||||
* @param iterable $subset
|
||||
* @param bool $strict
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(iterable $subset, bool $strict = false)
|
||||
{
|
||||
$this->strict = $strict;
|
||||
$this->subset = $subset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the constraint for parameter $other.
|
||||
*
|
||||
* If $returnResult is set to false (the default), an exception is thrown
|
||||
* in case of a failure. null is returned otherwise.
|
||||
*
|
||||
* If $returnResult is true, the result of the evaluation is returned as
|
||||
* a boolean value instead: true in case of success, false in case of a
|
||||
* failure.
|
||||
*
|
||||
* @param mixed $other
|
||||
* @param string $description
|
||||
* @param bool $returnResult
|
||||
* @return bool|null
|
||||
*
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function evaluate($other, string $description = '', bool $returnResult = false): ?bool
|
||||
{
|
||||
// type cast $other & $this->subset as an array to allow
|
||||
// support in standard array functions.
|
||||
$other = $this->toArray($other);
|
||||
$this->subset = $this->toArray($this->subset);
|
||||
|
||||
$patched = array_replace_recursive($other, $this->subset);
|
||||
|
||||
if ($this->strict) {
|
||||
$result = $other === $patched;
|
||||
} else {
|
||||
$result = $other == $patched;
|
||||
}
|
||||
|
||||
if ($returnResult) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (! $result) {
|
||||
$f = new ComparisonFailure(
|
||||
$patched,
|
||||
$other,
|
||||
var_export($patched, true),
|
||||
var_export($other, true)
|
||||
);
|
||||
|
||||
$this->fail($other, $description, $f);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the constraint.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function toString(): string
|
||||
{
|
||||
return 'has the subset '.$this->exporter()->export($this->subset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the failure.
|
||||
*
|
||||
* The beginning of failure messages is "Failed asserting that" in most
|
||||
* cases. This method should return the second part of that sentence.
|
||||
*
|
||||
* @param mixed $other
|
||||
* @return string
|
||||
*
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
protected function failureDescription($other): string
|
||||
{
|
||||
return 'an array '.$this->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the failure.
|
||||
*
|
||||
* The beginning of failure messages is "Failed asserting that" in most
|
||||
* cases. This method should return the second part of that sentence.
|
||||
*
|
||||
* @param iterable $other
|
||||
* @return array
|
||||
*/
|
||||
private function toArray(iterable $other): array
|
||||
{
|
||||
if (is_array($other)) {
|
||||
return $other;
|
||||
}
|
||||
|
||||
if ($other instanceof ArrayObject) {
|
||||
return $other->getArrayCopy();
|
||||
}
|
||||
|
||||
if ($other instanceof Traversable) {
|
||||
return iterator_to_array($other);
|
||||
}
|
||||
|
||||
// Keep BC even if we know that array would not be the expected one
|
||||
return (array) $other;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* @internal This class is not meant to be used or overwritten outside the framework itself.
|
||||
*/
|
||||
final class ArraySubset extends Constraint
|
||||
{
|
||||
/**
|
||||
* @var iterable
|
||||
*/
|
||||
private $subset;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $strict;
|
||||
|
||||
/**
|
||||
* Create a new array subset constraint instance.
|
||||
*
|
||||
* @param iterable $subset
|
||||
* @param bool $strict
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(iterable $subset, bool $strict = false)
|
||||
{
|
||||
$this->strict = $strict;
|
||||
$this->subset = $subset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the constraint for parameter $other.
|
||||
*
|
||||
* If $returnResult is set to false (the default), an exception is thrown
|
||||
* in case of a failure. null is returned otherwise.
|
||||
*
|
||||
* If $returnResult is true, the result of the evaluation is returned as
|
||||
* a boolean value instead: true in case of success, false in case of a
|
||||
* failure.
|
||||
*
|
||||
* @param mixed $other
|
||||
* @param string $description
|
||||
* @param bool $returnResult
|
||||
* @return bool|null
|
||||
*
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function evaluate($other, string $description = '', bool $returnResult = false)
|
||||
{
|
||||
// type cast $other & $this->subset as an array to allow
|
||||
// support in standard array functions.
|
||||
$other = $this->toArray($other);
|
||||
$this->subset = $this->toArray($this->subset);
|
||||
|
||||
$patched = array_replace_recursive($other, $this->subset);
|
||||
|
||||
if ($this->strict) {
|
||||
$result = $other === $patched;
|
||||
} else {
|
||||
$result = $other == $patched;
|
||||
}
|
||||
|
||||
if ($returnResult) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (! $result) {
|
||||
$f = new ComparisonFailure(
|
||||
$patched,
|
||||
$other,
|
||||
var_export($patched, true),
|
||||
var_export($other, true)
|
||||
);
|
||||
|
||||
$this->fail($other, $description, $f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the constraint.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function toString(): string
|
||||
{
|
||||
return 'has the subset '.$this->exporter()->export($this->subset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the failure.
|
||||
*
|
||||
* The beginning of failure messages is "Failed asserting that" in most
|
||||
* cases. This method should return the second part of that sentence.
|
||||
*
|
||||
* @param mixed $other
|
||||
* @return string
|
||||
*
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
protected function failureDescription($other): string
|
||||
{
|
||||
return 'an array '.$this->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the failure.
|
||||
*
|
||||
* The beginning of failure messages is "Failed asserting that" in most
|
||||
* cases. This method should return the second part of that sentence.
|
||||
*
|
||||
* @param iterable $other
|
||||
* @return array
|
||||
*/
|
||||
private function toArray(iterable $other): array
|
||||
{
|
||||
if (is_array($other)) {
|
||||
return $other;
|
||||
}
|
||||
|
||||
if ($other instanceof ArrayObject) {
|
||||
return $other->getArrayCopy();
|
||||
}
|
||||
|
||||
if ($other instanceof Traversable) {
|
||||
return iterator_to_array($other);
|
||||
}
|
||||
|
||||
// Keep BC even if we know that array would not be the expected one
|
||||
return (array) $other;
|
||||
}
|
||||
}
|
||||
}
|
||||
83
vendor/laravel/framework/src/Illuminate/Testing/Constraints/CountInDatabase.php
vendored
Normal file
83
vendor/laravel/framework/src/Illuminate/Testing/Constraints/CountInDatabase.php
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Testing\Constraints;
|
||||
|
||||
use Illuminate\Database\Connection;
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use ReflectionClass;
|
||||
|
||||
class CountInDatabase extends Constraint
|
||||
{
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Illuminate\Database\Connection
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* The expected table entries count that will be checked against the actual count.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expectedCount;
|
||||
|
||||
/**
|
||||
* The actual table entries count that will be checked against the expected count.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $actualCount;
|
||||
|
||||
/**
|
||||
* Create a new constraint instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $database
|
||||
* @param int $expectedCount
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Connection $database, int $expectedCount)
|
||||
{
|
||||
$this->expectedCount = $expectedCount;
|
||||
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the expected and actual count are equal.
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public function matches($table): bool
|
||||
{
|
||||
$this->actualCount = $this->database->table($table)->count();
|
||||
|
||||
return $this->actualCount === $this->expectedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description of the failure.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function failureDescription($table): string
|
||||
{
|
||||
return sprintf(
|
||||
"table [%s] matches expected entries count of %s. Entries found: %s.\n",
|
||||
$table, $this->expectedCount, $this->actualCount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the object.
|
||||
*
|
||||
* @param int $options
|
||||
* @return string
|
||||
*/
|
||||
public function toString($options = 0): string
|
||||
{
|
||||
return (new ReflectionClass($this))->name;
|
||||
}
|
||||
}
|
||||
116
vendor/laravel/framework/src/Illuminate/Testing/Constraints/HasInDatabase.php
vendored
Normal file
116
vendor/laravel/framework/src/Illuminate/Testing/Constraints/HasInDatabase.php
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Testing\Constraints;
|
||||
|
||||
use Illuminate\Database\Connection;
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
|
||||
class HasInDatabase extends Constraint
|
||||
{
|
||||
/**
|
||||
* Number of records that will be shown in the console in case of failure.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $show = 3;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Illuminate\Database\Connection
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* The data that will be used to narrow the search in the database table.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Create a new constraint instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $database
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Connection $database, array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the data is found in the given table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public function matches($table): bool
|
||||
{
|
||||
return $this->database->table($table)->where($this->data)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description of the failure.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function failureDescription($table): string
|
||||
{
|
||||
return sprintf(
|
||||
"a row in the table [%s] matches the attributes %s.\n\n%s",
|
||||
$table, $this->toString(JSON_PRETTY_PRINT), $this->getAdditionalInfo($table)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional info about the records found in the database table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function getAdditionalInfo($table)
|
||||
{
|
||||
$query = $this->database->table($table);
|
||||
|
||||
$similarResults = $query->where(
|
||||
array_key_first($this->data),
|
||||
$this->data[array_key_first($this->data)]
|
||||
)->limit($this->show)->get();
|
||||
|
||||
if ($similarResults->isNotEmpty()) {
|
||||
$description = 'Found similar results: '.json_encode($similarResults, JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
$query = $this->database->table($table);
|
||||
|
||||
$results = $query->limit($this->show)->get();
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
return 'The table is empty.';
|
||||
}
|
||||
|
||||
$description = 'Found: '.json_encode($results, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
if ($query->count() > $this->show) {
|
||||
$description .= sprintf(' and %s others', $query->count() - $this->show);
|
||||
}
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the object.
|
||||
*
|
||||
* @param int $options
|
||||
* @return string
|
||||
*/
|
||||
public function toString($options = 0): string
|
||||
{
|
||||
return json_encode($this->data, $options);
|
||||
}
|
||||
}
|
||||
88
vendor/laravel/framework/src/Illuminate/Testing/Constraints/SeeInOrder.php
vendored
Normal file
88
vendor/laravel/framework/src/Illuminate/Testing/Constraints/SeeInOrder.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Testing\Constraints;
|
||||
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use ReflectionClass;
|
||||
|
||||
class SeeInOrder extends Constraint
|
||||
{
|
||||
/**
|
||||
* The string under validation.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* The last value that failed to pass validation.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $failedValue;
|
||||
|
||||
/**
|
||||
* Create a new constraint instance.
|
||||
*
|
||||
* @param string $content
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the rule passes validation.
|
||||
*
|
||||
* @param array $values
|
||||
* @return bool
|
||||
*/
|
||||
public function matches($values): bool
|
||||
{
|
||||
$position = 0;
|
||||
|
||||
foreach ($values as $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$valuePosition = mb_strpos($this->content, $value, $position);
|
||||
|
||||
if ($valuePosition === false || $valuePosition < $position) {
|
||||
$this->failedValue = $value;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$position = $valuePosition + mb_strlen($value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description of the failure.
|
||||
*
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function failureDescription($values): string
|
||||
{
|
||||
return sprintf(
|
||||
'Failed asserting that \'%s\' contains "%s" in specified order.',
|
||||
$this->content,
|
||||
$this->failedValue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString(): string
|
||||
{
|
||||
return (new ReflectionClass($this))->name;
|
||||
}
|
||||
}
|
||||
117
vendor/laravel/framework/src/Illuminate/Testing/Constraints/SoftDeletedInDatabase.php
vendored
Normal file
117
vendor/laravel/framework/src/Illuminate/Testing/Constraints/SoftDeletedInDatabase.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Testing\Constraints;
|
||||
|
||||
use Illuminate\Database\Connection;
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
|
||||
class SoftDeletedInDatabase extends Constraint
|
||||
{
|
||||
/**
|
||||
* Number of records that will be shown in the console in case of failure.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $show = 3;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Illuminate\Database\Connection
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* The data that will be used to narrow the search in the database table.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* The name of the column that indicates soft deletion has occurred.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $deletedAtColumn;
|
||||
|
||||
/**
|
||||
* Create a new constraint instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $database
|
||||
* @param array $data
|
||||
* @param string $deletedAtColumn
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Connection $database, array $data, string $deletedAtColumn)
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
$this->database = $database;
|
||||
|
||||
$this->deletedAtColumn = $deletedAtColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the data is found in the given table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public function matches($table): bool
|
||||
{
|
||||
return $this->database->table($table)
|
||||
->where($this->data)
|
||||
->whereNotNull($this->deletedAtColumn)
|
||||
->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description of the failure.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function failureDescription($table): string
|
||||
{
|
||||
return sprintf(
|
||||
"any soft deleted row in the table [%s] matches the attributes %s.\n\n%s",
|
||||
$table, $this->toString(), $this->getAdditionalInfo($table)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional info about the records found in the database table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function getAdditionalInfo($table)
|
||||
{
|
||||
$query = $this->database->table($table);
|
||||
|
||||
$results = $query->limit($this->show)->get();
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
return 'The table is empty';
|
||||
}
|
||||
|
||||
$description = 'Found: '.json_encode($results, JSON_PRETTY_PRINT);
|
||||
|
||||
if ($query->count() > $this->show) {
|
||||
$description .= sprintf(' and %s others', $query->count() - $this->show);
|
||||
}
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString(): string
|
||||
{
|
||||
return json_encode($this->data);
|
||||
}
|
||||
}
|
||||
21
vendor/laravel/framework/src/Illuminate/Testing/LICENSE.md
vendored
Normal file
21
vendor/laravel/framework/src/Illuminate/Testing/LICENSE.md
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Taylor Otwell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
348
vendor/laravel/framework/src/Illuminate/Testing/PendingCommand.php
vendored
Normal file
348
vendor/laravel/framework/src/Illuminate/Testing/PendingCommand.php
vendored
Normal file
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Testing;
|
||||
|
||||
use Illuminate\Console\OutputStyle;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Mockery;
|
||||
use Mockery\Exception\NoMatchingExpectationException;
|
||||
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
||||
class PendingCommand
|
||||
{
|
||||
/**
|
||||
* The test being run.
|
||||
*
|
||||
* @var \Illuminate\Foundation\Testing\TestCase
|
||||
*/
|
||||
public $test;
|
||||
|
||||
/**
|
||||
* The application instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Container\Container
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* The command to run.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* The parameters to pass to the command.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* The expected exit code.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expectedExitCode;
|
||||
|
||||
/**
|
||||
* Determine if command has executed.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hasExecuted = false;
|
||||
|
||||
/**
|
||||
* Create a new pending console command run.
|
||||
*
|
||||
* @param \PHPUnit\Framework\TestCase $test
|
||||
* @param \Illuminate\Contracts\Container\Container $app
|
||||
* @param string $command
|
||||
* @param array $parameters
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(PHPUnitTestCase $test, Container $app, $command, $parameters)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->test = $test;
|
||||
$this->command = $command;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify an expected question that will be asked when the command runs.
|
||||
*
|
||||
* @param string $question
|
||||
* @param string|bool $answer
|
||||
* @return $this
|
||||
*/
|
||||
public function expectsQuestion($question, $answer)
|
||||
{
|
||||
$this->test->expectedQuestions[] = [$question, $answer];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify an expected confirmation question that will be asked when the command runs.
|
||||
*
|
||||
* @param string $question
|
||||
* @param string $answer
|
||||
* @return $this
|
||||
*/
|
||||
public function expectsConfirmation($question, $answer = 'no')
|
||||
{
|
||||
return $this->expectsQuestion($question, strtolower($answer) === 'yes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify an expected choice question with expected answers that will be asked/shown when the command runs.
|
||||
*
|
||||
* @param string $question
|
||||
* @param string|array $answer
|
||||
* @param array $answers
|
||||
* @param bool $strict
|
||||
* @return $this
|
||||
*/
|
||||
public function expectsChoice($question, $answer, $answers, $strict = false)
|
||||
{
|
||||
$this->test->expectedChoices[$question] = [
|
||||
'expected' => $answers,
|
||||
'strict' => $strict,
|
||||
];
|
||||
|
||||
return $this->expectsQuestion($question, $answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify output that should be printed when the command runs.
|
||||
*
|
||||
* @param string $output
|
||||
* @return $this
|
||||
*/
|
||||
public function expectsOutput($output)
|
||||
{
|
||||
$this->test->expectedOutput[] = $output;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a table that should be printed when the command runs.
|
||||
*
|
||||
* @param array $headers
|
||||
* @param \Illuminate\Contracts\Support\Arrayable|array $rows
|
||||
* @param string $tableStyle
|
||||
* @param array $columnStyles
|
||||
* @return $this
|
||||
*/
|
||||
public function expectsTable($headers, $rows, $tableStyle = 'default', array $columnStyles = [])
|
||||
{
|
||||
$this->test->expectedTables[] = [
|
||||
'headers' => (array) $headers,
|
||||
'rows' => $rows instanceof Arrayable ? $rows->toArray() : $rows,
|
||||
'tableStyle' => $tableStyle,
|
||||
'columnStyles' => $columnStyles,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the command has the given exit code.
|
||||
*
|
||||
* @param int $exitCode
|
||||
* @return $this
|
||||
*/
|
||||
public function assertExitCode($exitCode)
|
||||
{
|
||||
$this->expectedExitCode = $exitCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \Mockery\Exception\NoMatchingExpectationException
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->hasExecuted = true;
|
||||
|
||||
$mock = $this->mockConsoleOutput();
|
||||
|
||||
try {
|
||||
$exitCode = $this->app->make(Kernel::class)->call($this->command, $this->parameters, $mock);
|
||||
} catch (NoMatchingExpectationException $e) {
|
||||
if ($e->getMethodName() === 'askQuestion') {
|
||||
$this->test->fail('Unexpected question "'.$e->getActualArguments()[0]->getQuestion().'" was asked.');
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($this->expectedExitCode !== null) {
|
||||
$this->test->assertEquals(
|
||||
$this->expectedExitCode, $exitCode,
|
||||
"Expected status code {$this->expectedExitCode} but received {$exitCode}."
|
||||
);
|
||||
}
|
||||
|
||||
$this->verifyExpectations();
|
||||
|
||||
return $exitCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if expected questions / choices / outputs are fulfilled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function verifyExpectations()
|
||||
{
|
||||
if (count($this->test->expectedQuestions)) {
|
||||
$this->test->fail('Question "'.Arr::first($this->test->expectedQuestions)[0].'" was not asked.');
|
||||
}
|
||||
|
||||
if (count($this->test->expectedChoices) > 0) {
|
||||
foreach ($this->test->expectedChoices as $question => $answers) {
|
||||
$assertion = $answers['strict'] ? 'assertEquals' : 'assertEqualsCanonicalizing';
|
||||
|
||||
$this->test->{$assertion}(
|
||||
$answers['expected'],
|
||||
$answers['actual'],
|
||||
'Question "'.$question.'" has different options.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->test->expectedOutput)) {
|
||||
$this->test->fail('Output "'.Arr::first($this->test->expectedOutput).'" was not printed.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock the application's console output.
|
||||
*
|
||||
* @return \Mockery\MockInterface
|
||||
*/
|
||||
protected function mockConsoleOutput()
|
||||
{
|
||||
$mock = Mockery::mock(OutputStyle::class.'[askQuestion]', [
|
||||
(new ArrayInput($this->parameters)), $this->createABufferedOutputMock(),
|
||||
]);
|
||||
|
||||
foreach ($this->test->expectedQuestions as $i => $question) {
|
||||
$mock->shouldReceive('askQuestion')
|
||||
->once()
|
||||
->ordered()
|
||||
->with(Mockery::on(function ($argument) use ($question) {
|
||||
if (isset($this->test->expectedChoices[$question[0]])) {
|
||||
$this->test->expectedChoices[$question[0]]['actual'] = $argument->getAutocompleterValues();
|
||||
}
|
||||
|
||||
return $argument->getQuestion() == $question[0];
|
||||
}))
|
||||
->andReturnUsing(function () use ($question, $i) {
|
||||
unset($this->test->expectedQuestions[$i]);
|
||||
|
||||
return $question[1];
|
||||
});
|
||||
}
|
||||
|
||||
$this->app->bind(OutputStyle::class, function () use ($mock) {
|
||||
return $mock;
|
||||
});
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock for the buffered output.
|
||||
*
|
||||
* @return \Mockery\MockInterface
|
||||
*/
|
||||
private function createABufferedOutputMock()
|
||||
{
|
||||
$mock = Mockery::mock(BufferedOutput::class.'[doWrite]')
|
||||
->shouldAllowMockingProtectedMethods()
|
||||
->shouldIgnoreMissing();
|
||||
|
||||
$this->applyTableOutputExpectations($mock);
|
||||
|
||||
foreach ($this->test->expectedOutput as $i => $output) {
|
||||
$mock->shouldReceive('doWrite')
|
||||
->once()
|
||||
->ordered()
|
||||
->with($output, Mockery::any())
|
||||
->andReturnUsing(function () use ($i) {
|
||||
unset($this->test->expectedOutput[$i]);
|
||||
});
|
||||
}
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the output table expectations to the mock.
|
||||
*
|
||||
* @param \Mockery\MockInterface $mock
|
||||
* @return void
|
||||
*/
|
||||
private function applyTableOutputExpectations($mock)
|
||||
{
|
||||
foreach ($this->test->expectedTables as $consoleTable) {
|
||||
$table = (new Table($output = new BufferedOutput))
|
||||
->setHeaders($consoleTable['headers'])
|
||||
->setRows($consoleTable['rows'])
|
||||
->setStyle($consoleTable['tableStyle']);
|
||||
|
||||
foreach ($consoleTable['columnStyles'] as $columnIndex => $columnStyle) {
|
||||
$table->setColumnStyle($columnIndex, $columnStyle);
|
||||
}
|
||||
|
||||
$table->render();
|
||||
|
||||
$lines = array_filter(
|
||||
preg_split("/\n/", $output->fetch())
|
||||
);
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$this->expectsOutput($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the object's destruction.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->hasExecuted) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->run();
|
||||
}
|
||||
}
|
||||
1329
vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php
vendored
Normal file
1329
vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
43
vendor/laravel/framework/src/Illuminate/Testing/composer.json
vendored
Normal file
43
vendor/laravel/framework/src/Illuminate/Testing/composer.json
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "illuminate/testing",
|
||||
"description": "The Illuminate Testing package.",
|
||||
"license": "MIT",
|
||||
"homepage": "https://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2.5|^8.0",
|
||||
"illuminate/contracts": "^7.0",
|
||||
"illuminate/support": "^7.0",
|
||||
"symfony/polyfill-php73": "^1.17"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Testing\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "7.x-dev"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"illuminate/console": "Required to assert console commands (^7.0).",
|
||||
"illuminate/database": "Required to assert databases (^7.0).",
|
||||
"illuminate/http": "Required to assert responses (^7.0).",
|
||||
"mockery/mockery": "Required to use mocking (~1.3.3|^1.4.2).",
|
||||
"phpunit/phpunit": "Required to use assertions and run tests (^8.4|^9.3.3)."
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
Reference in New Issue
Block a user