zenstruck /
foundry
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Zenstruck\Foundry\Tests\Functional; |
||||
| 4 | |||||
| 5 | use Zenstruck\Foundry\AnonymousFactory; |
||||
| 6 | use Zenstruck\Foundry\Tests\Fixtures\Entity\Category; |
||||
| 7 | use Zenstruck\Foundry\Tests\Fixtures\Entity\Contact; |
||||
| 8 | use Zenstruck\Foundry\Tests\Fixtures\Entity\Post; |
||||
| 9 | use Zenstruck\Foundry\Tests\Fixtures\Factories\CategoryFactory; |
||||
| 10 | use Zenstruck\Foundry\Tests\Fixtures\Factories\PostFactory; |
||||
| 11 | |||||
| 12 | /** |
||||
| 13 | * @author Kevin Bond <[email protected]> |
||||
| 14 | */ |
||||
| 15 | final class ORMProxyTest extends ProxyTest |
||||
| 16 | { |
||||
| 17 | protected function setUp(): void |
||||
| 18 | { |
||||
| 19 | if (false === \getenv('DATABASE_URL')) { |
||||
| 20 | self::markTestSkipped('doctrine/orm not enabled.'); |
||||
| 21 | } |
||||
| 22 | } |
||||
| 23 | |||||
| 24 | /** |
||||
| 25 | * @test |
||||
| 26 | * @requires PHP >= 7.4 |
||||
| 27 | */ |
||||
| 28 | public function cannot_convert_to_string_if_underlying_object_cant(): void |
||||
| 29 | { |
||||
| 30 | $this->expectException(\RuntimeException::class); |
||||
| 31 | $this->expectExceptionMessage(\sprintf('Proxied object "%s" cannot be converted to a string.', Category::class)); |
||||
| 32 | |||||
| 33 | (string) CategoryFactory::createOne(); |
||||
| 34 | } |
||||
| 35 | |||||
| 36 | /** |
||||
| 37 | * @test |
||||
| 38 | * @requires PHP < 7.4 |
||||
| 39 | */ |
||||
| 40 | public function on_php_versions_less_than_7_4_if_underlying_object_is_missing_to_string_proxy_to_string_returns_note(): void |
||||
| 41 | { |
||||
| 42 | $this->assertSame('(no __toString)', (string) CategoryFactory::createOne()); |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | /** |
||||
| 46 | * @test |
||||
| 47 | */ |
||||
| 48 | public function can_autorefresh_entity_with_embedded_object(): void |
||||
| 49 | { |
||||
| 50 | $contact = AnonymousFactory::new(Contact::class)->create(['name' => 'john']) |
||||
| 51 | ->enableAutoRefresh() |
||||
| 52 | ; |
||||
| 53 | |||||
| 54 | $this->assertSame('john', $contact->getName()); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 55 | |||||
| 56 | // I discovered when autorefreshing the second time, the embedded |
||||
| 57 | // object is included in the changeset when using UOW::recomputeSingleEntityChangeSet(). |
||||
| 58 | // Changing to UOW::computeChangeSet() fixes this. |
||||
| 59 | $this->assertSame('john', $contact->getName()); |
||||
| 60 | $this->assertNull($contact->getAddress()->getValue()); |
||||
|
0 ignored issues
–
show
The method
getAddress() does not exist on Zenstruck\Foundry\Proxy. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 61 | |||||
| 62 | $contact->getAddress()->setValue('address'); |
||||
| 63 | $contact->save(); |
||||
| 64 | |||||
| 65 | $this->assertSame('address', $contact->getAddress()->getValue()); |
||||
| 66 | |||||
| 67 | self::ensureKernelShutdown(); |
||||
| 68 | self::bootKernel(); |
||||
| 69 | |||||
| 70 | $this->assertSame('address', $contact->getAddress()->getValue()); |
||||
| 71 | } |
||||
| 72 | |||||
| 73 | protected function postFactoryClass(): string |
||||
| 74 | { |
||||
| 75 | return PostFactory::class; |
||||
| 76 | } |
||||
| 77 | |||||
| 78 | protected function postClass(): string |
||||
| 79 | { |
||||
| 80 | return Post::class; |
||||
| 81 | } |
||||
| 82 | |||||
| 83 | protected function registryServiceId(): string |
||||
| 84 | { |
||||
| 85 | return 'doctrine'; |
||||
| 86 | } |
||||
| 87 | } |
||||
| 88 |