Failed asserting that two objects are equal PHP Codeception

Viewed 115

I wrote a small test to check that the data returned by the function meets my expectations.

/**
 * @dataProvider successDataProvider
 */
public function testSuccessProvide(array $responses, ?MyResponse $myResponse): void
{
    $dataProvider = new MyDataProvider($this->tester->mockGuzzleClient($responses));
    $dataProviderResponse = $dataProvider->provide(Stub::makeEmpty(CheckRequest::class, [
        'nameUser' => new Name('test', 'test', 'test')
    ]));
    $this->assertEqualsCanonicalizing($myResponse, $dataProviderResponse);
}

My function that contains the objects that I prepared as expected, the correct data that the function returns

public function successDataProvider(): array
    {
        return [
            [
                'httpResponses' => [
                    $this->createSuccessResponse('simple')
                ],
                'dataProviderResponse' => new MyResponse(
                    [
                        (object)[
                            "type" => "Ответчик",
                            "subType" => "РешенияПерв",
                            "year" => 2017,
                            "description" => "Оставить без изменения решение, а апелляционную жалобу - без удовлетворения (п.1 ст.269 АПК)",
                            "sum" => 10576596.8,
                            "count" => 1
                        ],
                        (object)[
                            "type" => "Ответчик",
                            "subType" => "РешенияПерв",
                            "year" => 2017,
                            "description" => "Оставить решение (определение) суда первой инстанции и постановление суда апелляционной инстанции без изменения, а кассационную жалобу - без удовлетворения",
                            "sum" => 3519672.72,
                            "count" => 1
                        ],
                        (object)[
                            "type" => "Ответчик",
                            "subType" => "РешенияАпп",
                            "year" => 2017,
                            "description" => "Оставить без изменения решение, а апелляционную жалобу - без удовлетворения (п.1 ст.269 АПК)",
                            "sum" => 10576596.8,
                            "count" => 1
                        ],
                        (object)[
                            "type" => "Ответчик",
                            "subType" => "РешенияАпп",
                            "year" => 2017,
                            "description" => "Оставить решение (определение) суда первой инстанции и постановление суда апелляционной инстанции без изменения, а кассационную жалобу - без удовлетворения",
                            "sum" => 3519672.72,
                            "count" => 1
                        ],
                        (object)[
                            "type" => "Ответчик",
                            "subType" => "РешенияКасс",
                            "year" => 2017,
                            "description" => "Оставить решение (определение) суда первой инстанции и постановление суда апелляционной инстанции без изменения, а кассационную жалобу - без удовлетворения",
                            "sum" => 3519672.72,
                            "count" => 1
                        ],
                        (object)[
                            "type" => "Ответчик",
                            "subType" => "РешенияПерв",
                            "year" => 2021,
                            "description" => "Нет решения",
                            "sum" => 44014383.56,
                            "count" => 1
                        ]
                    ]
                ),
            ]
        ];
    }

I have attached a picture on the left: my data, on the right data which is correct for the test. As you can see my data (stdClass Object & 000000001b2e5dd1000000001e790f83) does not match the result (namespace my function Object & 000000001b2e5d1d000000001e790f83)

enter image description here

I am getting an error like: "Failed asserting that two objects are equal." The question is, how can I compare two objects OR, how can I get rid of the namespace dependency in the test so that I was able to pass it successfully ?? Thanks in advance for your answer!

1 Answers

You should not expect a (object) return, you return data, say ClassResponseData, and expect to get only the ClassResponseData object. An object is a specific instance of a class. For example, your particular machine or data response. You are expecting something specific, but in the test you just sent an object and are expecting a Class object.

public function successDataProvider(): array
    {
        return [
            [
                'httpResponses' => [
                    $this->createSuccessResponse('simple')
                ],
                'dataProviderResponse' => new ClassResponseData(
                    [
                        new ClassResponseData(
                            "Ответчик",
                            "РешенияПерв",
                            2017,
                            "Оставить без изменения решение, а апелляционную жалобу - без удовлетворения (п.1 ст.269 АПК)",
                            10576596.8,
                            1
                        ),
                        new ClassResponseData(...),
                        
                    ]
                ),
            ],
            ...
        ];
    }
Related