3232#[CoversClass(AbstractExecutor::class)]
3333class AbstractExecutorTest extends TestCase
3434{
35- /**
36- * @var \Cake\Datasource\ConnectionInterface&\PHPUnit\Framework\MockObject\MockObject
37- */
38- protected ConnectionInterface $ Connection ;
39-
4035 protected AbstractExecutor $ Executor ;
4136
4237 /**
43- * {@inheritDoc}
44- *
45- * @throws \PHPUnit\Framework\MockObject\Exception
38+ * @inheritDoc
4639 */
4740 protected function setUp (): void
4841 {
49- $ this -> Connection = $ this ->createMock (ConnectionInterface::class);
42+ $ Connection = $ this ->createStub (ConnectionInterface::class);
5043
51- $ this ->Executor = new class ($ this -> Connection ) extends AbstractExecutor {
44+ $ this ->Executor = new class ($ Connection ) extends AbstractExecutor {
5245 };
5346 }
5447
@@ -64,7 +57,6 @@ protected function setUp(): void
6457 public function testCallMagicMethod (string $ expectedNewMethod , string $ oldMethod ): void
6558 {
6659 $ Executor = $ this ->createPartialMock (AbstractExecutor::class, [$ expectedNewMethod ]);
67-
6860 $ Executor
6961 ->expects ($ this ->once ())
7062 ->method ($ expectedNewMethod )
@@ -97,22 +89,19 @@ public function testImplementedEvents(): void
9789 #[TestWith(['\'sqlite3-binary \' my-database .dump | \'bzip2-binary \' > \'filename.sql.bz2 \'' , 'filename.sql.bz2 ' ])]
9890 public function testGetExportCommand (string $ expectedExportCommand , string $ filename ): void
9991 {
100- $ Executor = $ this ->getMockBuilder (AbstractExecutor::class)
101- ->setConstructorArgs ([$ this ->Connection , 'Sqlite ' ])
102- ->onlyMethods (['getBinary ' , 'getConfig ' ])
103- ->getMock ();
92+ $ Connection = $ this ->createStub (ConnectionInterface::class);
10493
105- $ Executor
106- ->expects ($ this ->any ())
107- ->method ('getBinary ' )
108- ->willReturnCallback (function (Compression |string $ binaryName ): string {
94+ $ Executor = new class ($ Connection , 'Sqlite ' ) extends AbstractExecutor {
95+ public function getBinary (string |Compression $ binaryName ): string
96+ {
10997 return ($ binaryName instanceof Compression ? strtolower ($ binaryName ->name ) : $ binaryName ) . '-binary ' ;
110- });
98+ }
11199
112- $ Executor
113- ->expects ($ this ->any ())
114- ->method ('getConfig ' )
115- ->willReturnCallback (fn (string $ key ): string => 'my- ' . $ key );
100+ public function getConfig (string $ key ): string
101+ {
102+ return 'my- ' . $ key ;
103+ }
104+ };
116105
117106 $ result = $ Executor ->getExportCommand ($ filename );
118107
@@ -128,22 +117,19 @@ public function testGetExportCommand(string $expectedExportCommand, string $file
128117 #[TestWith(['\'bzip2-binary \' -dc \'filename.sql.bz2 \' | \'sqlite3-binary \' my-database ' , 'filename.sql.bz2 ' ])]
129118 public function testGetImportCommand (string $ expectedImportCommand , string $ filename ): void
130119 {
131- $ Executor = $ this ->getMockBuilder (AbstractExecutor::class)
132- ->setConstructorArgs ([$ this ->Connection , 'Sqlite ' ])
133- ->onlyMethods (['getBinary ' , 'getConfig ' ])
134- ->getMock ();
120+ $ Connection = $ this ->createStub (ConnectionInterface::class);
135121
136- $ Executor
137- ->expects ($ this ->any ())
138- ->method ('getBinary ' )
139- ->willReturnCallback (function (Compression |string $ binaryName ): string {
122+ $ Executor = new class ($ Connection , 'Sqlite ' ) extends AbstractExecutor {
123+ public function getBinary (string |Compression $ binaryName ): string
124+ {
140125 return ($ binaryName instanceof Compression ? strtolower ($ binaryName ->name ) : $ binaryName ) . '-binary ' ;
141- });
126+ }
142127
143- $ Executor
144- ->expects ($ this ->any ())
145- ->method ('getConfig ' )
146- ->willReturnCallback (fn (string $ key ): string => 'my- ' . $ key );
128+ public function getConfig (string $ key ): string
129+ {
130+ return 'my- ' . $ key ;
131+ }
132+ };
147133
148134 $ result = $ Executor ->getImportCommand ($ filename );
149135
@@ -175,12 +161,16 @@ public function testGetBinaryNoExistingBinary(string $expectedBinaryName, string
175161 #[TestWith([null , 'noExisting ' ])]
176162 public function testGetConfig (?string $ expectedConfig , string $ configKey ): void
177163 {
178- $ this ->Connection
164+ $ Connection = $ this ->createMock (ConnectionInterface::class);
165+ $ Connection
179166 ->expects ($ this ->once ())
180167 ->method ('config ' )
181168 ->willReturn (['name ' => 'test ' ]);
182169
183- $ result = $ this ->Executor ->getConfig ($ configKey );
170+ $ Executor = new class ($ Connection ) extends AbstractExecutor {
171+ };
172+
173+ $ result = $ Executor ->getConfig ($ configKey );
184174 $ this ->assertSame ($ expectedConfig , $ result );
185175 }
186176}
0 commit comments