Merge pull request #566 from fabio-ivona/2.x-dynamic-properties-fix

2.x dynamic properties fix
This commit is contained in:
Nuno Maduro
2022-08-29 15:14:41 +01:00
committed by GitHub
4 changed files with 15 additions and 10 deletions

View File

@ -8,14 +8,9 @@ jobs:
strategy:
matrix:
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]
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 }}

View File

@ -186,7 +186,7 @@ final class TestCaseFactory
use Pest\TestSuite as __PestTestSuite;
$classAttributesCode
#[AllowDynamicProperties]
#[\AllowDynamicProperties]
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
$traitsCode

View File

@ -714,7 +714,7 @@ final class Expectation
*
* @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')) {
$valueAsArray = $this->value->toArray();
@ -743,11 +743,11 @@ final class Expectation
* Asserts that the value object matches a subset
* of the properties of an given object.
*
* @param iterable<string, mixed>|object $object
* @param iterable<string, mixed> $object
*
* @return Expectation<TValue>
*/
public function toMatchObject(iterable|object $object): Expectation
public function toMatchObject(iterable $object): Expectation
{
foreach ((array) $object as $property => $value) {
if (!is_object($this->value) && !is_string($this->value)) {

View File

@ -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 () {
expect($this->user)->toMatchObject([
'name' => 'Not the same name',