‪TYPO3CMS  11.5
LazyObjectStorageTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 class ‪LazyObjectStorageTest extends FunctionalTestCase
26 {
27  protected ‪$coreExtensionsToLoad = ['extbase'];
28  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
29 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36 
37  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/blogs.csv');
38  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/posts.csv');
39  }
40 
44  public function ‪serializeAndUnserialize(): void
45  {
46  $blog = new ‪Blog();
47  $blog->_setProperty('uid', 1);
48  $blog->_setProperty('posts', new ‪LazyObjectStorage($blog, 'posts', 10));
49 
50  $serialized = serialize($blog->getPosts());
51 
52  self::assertFalse(str_contains($serialized, 'dataMapper'), 'Assert that serialized object string does not contain dataMapper');
53 
55  $postsProxy = unserialize($serialized, ['allowed_classes' => true]);
56  self::assertInstanceOf(LazyObjectStorage::class, $postsProxy, 'Assert that $postsProxy is an instance of LazyObjectStorage');
57 
59  $posts = $postsProxy->toArray();
60 
61  self::assertInstanceOf(Post::class, $posts[0], 'Assert that $posts[0] is an instance of Post');
62  self::assertInstanceOf(Post::class, $posts[1], 'Assert that $posts[1] is an instance of Post');
63 
64  self::assertSame('Post1', $posts[0]->getTitle());
65  self::assertSame('Post2', $posts[1]->getTitle());
66  }
67 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest\serializeAndUnserialize
‪serializeAndUnserialize()
Definition: LazyObjectStorageTest.php:44
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest\$coreExtensionsToLoad
‪$coreExtensionsToLoad
Definition: LazyObjectStorageTest.php:27
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest\setUp
‪setUp()
Definition: LazyObjectStorageTest.php:33
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest\$testExtensionsToLoad
‪$testExtensionsToLoad
Definition: LazyObjectStorageTest.php:28
‪ExtbaseTeam\BlogExample\Domain\Model\Blog
Definition: Blog.php:29
‪ExtbaseTeam\BlogExample\Domain\Model\Post
Definition: Post.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:18
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage
Definition: LazyObjectStorage.php:32
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest
Definition: LazyObjectStorageTest.php:26