1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||||||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||||||
6 | */ |
||||||
7 | |||||||
8 | namespace SprykerTest\Zed\FileManager\Business\File; |
||||||
9 | |||||||
10 | use Codeception\Test\Unit; |
||||||
11 | use Generated\Shared\Transfer\FileInfoTransfer; |
||||||
12 | use Generated\Shared\Transfer\FileManagerDataTransfer; |
||||||
13 | use Generated\Shared\Transfer\FileTransfer; |
||||||
14 | use Spryker\Zed\FileManager\Business\File\FileReader; |
||||||
15 | use Spryker\Zed\FileManager\Business\FileContent\FileContentInterface; |
||||||
16 | use Spryker\Zed\FileManager\Persistence\FileManagerRepositoryInterface; |
||||||
17 | |||||||
18 | /** |
||||||
19 | * Auto-generated group annotations |
||||||
20 | * |
||||||
21 | * @group SprykerTest |
||||||
22 | * @group Zed |
||||||
23 | * @group FileManager |
||||||
24 | * @group Business |
||||||
25 | * @group File |
||||||
26 | * @group FileReaderTest |
||||||
27 | * Add your own group annotations below this line |
||||||
28 | */ |
||||||
29 | class FileReaderTest extends Unit |
||||||
30 | { |
||||||
31 | /** |
||||||
32 | * @return \Spryker\Zed\FileManager\Business\FileContent\FileContentInterface|\PHPUnit\Framework\MockObject\MockObject |
||||||
33 | */ |
||||||
34 | protected function createFileContentMock(): FileContentInterface |
||||||
35 | { |
||||||
36 | return $this->getMockBuilder(FileContentInterface::class)->getMock(); |
||||||
37 | } |
||||||
38 | |||||||
39 | /** |
||||||
40 | * @return \Spryker\Zed\FileManager\Persistence\FileManagerRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject |
||||||
41 | */ |
||||||
42 | protected function createFileManagerRepositoryMock(): FileManagerRepositoryInterface |
||||||
43 | { |
||||||
44 | return $this->getMockBuilder(FileManagerRepositoryInterface::class)->getMock(); |
||||||
45 | } |
||||||
46 | |||||||
47 | /** |
||||||
48 | * @return \Generated\Shared\Transfer\FileTransfer |
||||||
49 | */ |
||||||
50 | protected function getMockedFile(): FileTransfer |
||||||
51 | { |
||||||
52 | $fileTransfer = new FileTransfer(); |
||||||
53 | $fileTransfer->setFileName('test.txt'); |
||||||
54 | $fileTransfer->setIdFile(1); |
||||||
55 | |||||||
56 | $fileTransfer->addFileInfo($this->getMockedFileInfo()); |
||||||
57 | |||||||
58 | return $fileTransfer; |
||||||
59 | } |
||||||
60 | |||||||
61 | /** |
||||||
62 | * @return \Generated\Shared\Transfer\FileInfoTransfer |
||||||
63 | */ |
||||||
64 | protected function getMockedFileInfo(): FileInfoTransfer |
||||||
65 | { |
||||||
66 | $fileInfoTransfer = new FileInfoTransfer(); |
||||||
67 | $fileInfoTransfer->setIdFileInfo(1); |
||||||
68 | $fileInfoTransfer->setExtension('txt'); |
||||||
69 | $fileInfoTransfer->setVersionName('v. 1'); |
||||||
70 | $fileInfoTransfer->setVersion(1); |
||||||
71 | $fileInfoTransfer->setSize(1024); |
||||||
72 | $fileInfoTransfer->setStorageFileName('report.txt'); |
||||||
73 | |||||||
74 | return $fileInfoTransfer; |
||||||
75 | } |
||||||
76 | |||||||
77 | /** |
||||||
78 | * @param \Generated\Shared\Transfer\FileManagerDataTransfer $fileManagerDataTransfer |
||||||
79 | * |
||||||
80 | * @return void |
||||||
81 | */ |
||||||
82 | protected function assertFileInfo(FileManagerDataTransfer $fileManagerDataTransfer): void |
||||||
83 | { |
||||||
84 | $this->assertSame('the content of the file', $fileManagerDataTransfer->getContent()); |
||||||
85 | $this->assertSame('v. 1', $fileManagerDataTransfer->getFileInfo()->getVersionName()); |
||||||
86 | $this->assertSame(1024, $fileManagerDataTransfer->getFileInfo()->getSize()); |
||||||
87 | $this->assertSame(1, $fileManagerDataTransfer->getFileInfo()->getVersion()); |
||||||
88 | $this->assertSame('txt', $fileManagerDataTransfer->getFileInfo()->getExtension()); |
||||||
89 | $this->assertSame('report.txt', $fileManagerDataTransfer->getFileInfo()->getStorageFileName()); |
||||||
90 | } |
||||||
91 | |||||||
92 | /** |
||||||
93 | * @return void |
||||||
94 | */ |
||||||
95 | public function testRead(): void |
||||||
96 | { |
||||||
97 | $fileContentMock = $this->createFileContentMock(); |
||||||
98 | $fileManagerRepositoryMock = $this->createFileManagerRepositoryMock(); |
||||||
99 | |||||||
100 | $fileManagerRepositoryMock->expects($this->once()) |
||||||
101 | ->method('getFileByIdFileInfo') |
||||||
102 | ->willReturn($this->getMockedFile()); |
||||||
103 | |||||||
104 | $fileContentMock |
||||||
105 | ->method('read') |
||||||
0 ignored issues
–
show
|
|||||||
106 | ->willReturn('the content of the file'); |
||||||
107 | |||||||
108 | $fileReader = new FileReader($fileManagerRepositoryMock, $fileContentMock); |
||||||
109 | $this->assertFileInfo($fileReader->readFileByIdFileInfo(1)); |
||||||
110 | } |
||||||
111 | |||||||
112 | /** |
||||||
113 | * @return void |
||||||
114 | */ |
||||||
115 | public function testReadLatestByFileId(): void |
||||||
116 | { |
||||||
117 | $fileContentMock = $this->createFileContentMock(); |
||||||
118 | $fileManagerRepositoryMock = $this->createFileManagerRepositoryMock(); |
||||||
119 | |||||||
120 | $fileManagerRepositoryMock->expects($this->once()) |
||||||
121 | ->method('getLatestFileInfoByIdFile') |
||||||
122 | ->willReturn($this->getMockedFileInfo()); |
||||||
123 | |||||||
124 | $fileContentMock->expects($this->once()) |
||||||
0 ignored issues
–
show
The method
expects() does not exist on Spryker\Zed\FileManager\...nt\FileContentInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
125 | ->method('read') |
||||||
126 | ->willReturn('the content of the file'); |
||||||
127 | |||||||
128 | $fileReader = new FileReader($fileManagerRepositoryMock, $fileContentMock); |
||||||
129 | $this->assertFileInfo($fileReader->readLatestByFileId(1)); |
||||||
130 | } |
||||||
131 | } |
||||||
132 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.