mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
Merge pull request #566 from fabio-ivona/2.x-dynamic-properties-fix
2.x dynamic properties fix
This commit is contained in:
7
.github/workflows/tests.yml
vendored
7
.github/workflows/tests.yml
vendored
@ -8,14 +8,9 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest] # (macos-latest, windows-latest) 2.x-dev is under development
|
os: [ubuntu-latest] # (macos-latest, windows-latest) 2.x-dev is under development
|
||||||
php: ['8.1']
|
php: ['8.1', '8.2']
|
||||||
dependency-version: [prefer-lowest, prefer-stable]
|
dependency-version: [prefer-lowest, prefer-stable]
|
||||||
parallel: ['', '--parallel']
|
parallel: ['', '--parallel']
|
||||||
exclude:
|
|
||||||
- php: 8.1
|
|
||||||
os: macos-latest
|
|
||||||
- php: 8.1
|
|
||||||
os: windows-latest
|
|
||||||
|
|
||||||
name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} - ${{ matrix.parallel }}
|
name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} - ${{ matrix.parallel }}
|
||||||
|
|
||||||
|
|||||||
@ -186,7 +186,7 @@ final class TestCaseFactory
|
|||||||
use Pest\TestSuite as __PestTestSuite;
|
use Pest\TestSuite as __PestTestSuite;
|
||||||
|
|
||||||
$classAttributesCode
|
$classAttributesCode
|
||||||
#[AllowDynamicProperties]
|
#[\AllowDynamicProperties]
|
||||||
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
|
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
|
||||||
$traitsCode
|
$traitsCode
|
||||||
|
|
||||||
|
|||||||
@ -714,7 +714,7 @@ final class Expectation
|
|||||||
*
|
*
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toMatchArray(iterable|object $array): Expectation
|
public function toMatchArray(iterable $array): Expectation
|
||||||
{
|
{
|
||||||
if (is_object($this->value) && method_exists($this->value, 'toArray')) {
|
if (is_object($this->value) && method_exists($this->value, 'toArray')) {
|
||||||
$valueAsArray = $this->value->toArray();
|
$valueAsArray = $this->value->toArray();
|
||||||
@ -743,11 +743,11 @@ final class Expectation
|
|||||||
* Asserts that the value object matches a subset
|
* Asserts that the value object matches a subset
|
||||||
* of the properties of an given object.
|
* of the properties of an given object.
|
||||||
*
|
*
|
||||||
* @param iterable<string, mixed>|object $object
|
* @param iterable<string, mixed> $object
|
||||||
*
|
*
|
||||||
* @return Expectation<TValue>
|
* @return Expectation<TValue>
|
||||||
*/
|
*/
|
||||||
public function toMatchObject(iterable|object $object): Expectation
|
public function toMatchObject(iterable $object): Expectation
|
||||||
{
|
{
|
||||||
foreach ((array) $object as $property => $value) {
|
foreach ((array) $object as $property => $value) {
|
||||||
if (!is_object($this->value) && !is_string($this->value)) {
|
if (!is_object($this->value) && !is_string($this->value)) {
|
||||||
|
|||||||
@ -17,6 +17,16 @@ test('pass', function () {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('pass with class', function () {
|
||||||
|
expect(new class() {
|
||||||
|
public $name = 'Nuno';
|
||||||
|
public $email = 'enunomaduro@gmail.com';
|
||||||
|
})->toMatchObject([
|
||||||
|
'name' => 'Nuno',
|
||||||
|
'email' => 'enunomaduro@gmail.com',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect($this->user)->toMatchObject([
|
expect($this->user)->toMatchObject([
|
||||||
'name' => 'Not the same name',
|
'name' => 'Not the same name',
|
||||||
|
|||||||
Reference in New Issue
Block a user