‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪LazyObjectStorageTest extends FunctionalTestCase
29 {
30  protected array ‪$coreExtensionsToLoad = ['extbase'];
31 
32  protected array ‪$testExtensionsToLoad = [
33  'typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example',
34  ];
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  $this->importCSVDataSet(__DIR__ . '/Fixtures/LazyObjectStorageTestImport.csv');
40  $request = (new ‪ServerRequest())->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
41  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
42  }
43 
44  #[Test]
45  public function ‪serializeAndUnserialize(): void
46  {
47  $blog = new ‪Blog();
48  $blog->_setProperty('uid', 1);
49  $blog->_setProperty('posts', new ‪LazyObjectStorage($blog, 'posts', 10));
50 
51  $serialized = serialize($blog->getPosts());
52 
53  self::assertFalse(str_contains($serialized, 'dataMapper'), 'Assert that serialized object string does not contain dataMapper');
54 
56  $postsProxy = unserialize($serialized, ['allowed_classes' => true]);
57  self::assertInstanceOf(LazyObjectStorage::class, $postsProxy, 'Assert that $postsProxy is an instance of LazyObjectStorage');
58 
60  $posts = $postsProxy->toArray();
61 
62  self::assertInstanceOf(Post::class, $posts[0], 'Assert that $posts[0] is an instance of Post');
63  self::assertInstanceOf(Post::class, $posts[1], 'Assert that $posts[1] is an instance of Post');
64 
65  self::assertSame('Post1', $posts[0]->getTitle());
66  self::assertSame('Post2', $posts[1]->getTitle());
67  }
68 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest\serializeAndUnserialize
‪serializeAndUnserialize()
Definition: LazyObjectStorageTest.php:45
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest\setUp
‪setUp()
Definition: LazyObjectStorageTest.php:36
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: LazyObjectStorageTest.php:30
‪TYPO3Tests\BlogExample\Domain\Model\Post
Definition: Post.php:28
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:18
‪TYPO3Tests\BlogExample\Domain\Model\Blog
Definition: Blog.php:30
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage
Definition: LazyObjectStorage.php:36
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest
Definition: LazyObjectStorageTest.php:29
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyObjectStorageTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: LazyObjectStorageTest.php:32