feat(expect): adds toBe

This commit is contained in:
Nuno Maduro
2020-07-06 00:32:12 +02:00
parent 3eb0a95955
commit 01b9bab55f
5 changed files with 145 additions and 2 deletions

65
src/Expectation.php Normal file
View File

@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace Pest;
use PHPUnit\Framework\Assert;
/**
* @internal
*
* @property Expectation $not Creates the opposite expectation.
*/
final class Expectation
{
/**
* The expectation value.
*
* @var mixed
*/
private $value;
/**
* Creates a new expectation.
*
* @param mixed $value
*/
public function __construct($value)
{
$this->value = $value;
}
/**
* Creates the opposite expectation for the value.
*/
public function not(): OppositeExpectation
{
return new OppositeExpectation($this);
}
/**
* Asserts that two variables have the same type and
* value. Used on objects, it asserts that two
* variables reference the same object.
*
* @param mixed $value
*/
public function toBe($value): Expectation
{
Assert::assertSame($value, $this->value);
return $this;
}
/**
* Dynamically calls methods on the class without any arguments.
*
* @return Expectation
*/
public function __get(string $name)
{
/* @phpstan-ignore-next-line */
return $this->{$name}();
}
}