0

I upgraded Laravel from 5.8 to 6.0. I run unit tests in docker container using Composer 2 and directly with php vendor/bin/phpunit (doesn't matter). PHPunit version is 7.5.20. PHP version is 7.3. All unit tests that have entities with relations are unstable, meaning it can either fall of pass without any changes. The code looks like this:

$book = factory(Book::class)->create([
    'title' => 'test'
]);

I also tried to create related record directlt in the code:

$author = factory(Author::class)->create([])

$book = factory(Book::class)->create([
    'title' => 'test',
    'author' => $author->getKey()
]);

but it doesn't realy matter. Tests fail randomly. And every time it's either different one or non of them.

Hevyweb
  • 402
  • 1
  • 5
  • 18
  • 2
    Fail with what error? – Maksim Jul 21 '21 at 10:56
  • 1
    What does your test look like, what is the error that you get? – Dirk Scholten Jul 21 '21 at 11:55
  • It fails because method `getRelationValue($key);` in the Illuminate\Database\Eloquent\Concerns\HasAttributes returns null, and my code expects some entity. I call some method on that null and it fails. – Hevyweb Jul 21 '21 at 12:05
  • Which message gives the phpunit test-runner when you have those (random) failures? Is it always the same message? What was your previous Phpunit version? When you run the non-upgraded code with Phpunit 7.5.20 do you see the same behaviour? – hakre Jul 21 '21 at 12:27
  • PHPunit displays an error "Error: Call to a member function getKey() on null". PHPUnit vestion wasn't changed. – Hevyweb Jul 21 '21 at 12:43
  • 1
    That error actually is a PHP error. If you're looking for debugging help, I'd suggest the following PHP debugging reference on Stackoverflow: [Reference - What does this error mean in PHP?](https://stackoverflow.com/q/12769982/367456). You may want to edit the actual error message into the question and share your understanding of it with it (then perhaps followed up with what you have tried so far to deal with it). – hakre Jul 21 '21 at 18:43

1 Answers1

0

I found the issue. It's the performance upgrade - https://laravel.com/docs/6.x/upgrade#eloquent-primary-key-type For each entity that has string primary key I set

/**
 * The "type" of the primary key ID.
 *
 * @var string
 */
protected $keyType = 'string';
Hevyweb
  • 402
  • 1
  • 5
  • 18