2929 */
3030class BackupTraitTest extends TestCase
3131{
32- use BackupTrait;
32+ /**
33+ * @psalm-var trait-string<\DatabaseBackup\BackupTrait>
34+ */
35+ protected $ Trait ;
3336
3437 /**
3538 * Fixtures
36- * @var array
39+ * @var array<string>
3740 */
3841 public $ fixtures = [
3942 'core.Articles ' ,
4043 'core.Comments ' ,
4144 ];
4245
46+ /**
47+ * Called before every test method
48+ * @return void
49+ */
50+ public function setUp (): void
51+ {
52+ parent ::setUp ();
53+
54+ $ this ->Trait = $ this ->Trait ?: $ this ->getMockForTrait (BackupTrait::class);
55+ }
56+
4357 /**
4458 * Test for `getAbsolutePath()` method
4559 * @test
4660 */
4761 public function testGetAbsolutePath (): void
4862 {
4963 $ expected = Configure::read ('DatabaseBackup.target ' ) . DS . 'file.txt ' ;
50- $ this ->assertEquals ($ expected , $ this ->getAbsolutePath ('file.txt ' ));
51- $ this ->assertEquals ($ expected , $ this ->getAbsolutePath (Configure::read ('DatabaseBackup.target ' ) . DS . 'file.txt ' ));
64+ $ this ->assertEquals ($ expected , $ this ->Trait -> getAbsolutePath ('file.txt ' ));
65+ $ this ->assertEquals ($ expected , $ this ->Trait -> getAbsolutePath (Configure::read ('DatabaseBackup.target ' ) . DS . 'file.txt ' ));
5266 }
5367
5468 /**
@@ -65,7 +79,7 @@ public function testGetCompression(): void
6579 'backup.sql.gz ' => 'gzip ' ,
6680 'text.txt ' => null ,
6781 ] as $ filename => $ expectedCompression ) {
68- $ this ->assertEquals ($ expectedCompression , $ this ->getCompression ($ filename ));
82+ $ this ->assertEquals ($ expectedCompression , $ this ->Trait -> getCompression ($ filename ));
6983 }
7084 }
7185
@@ -76,13 +90,13 @@ public function testGetCompression(): void
7690 public function testGetConnection (): void
7791 {
7892 foreach ([null , Configure::read ('DatabaseBackup.connection ' )] as $ name ) {
79- $ connection = $ this ->getConnection ($ name );
93+ $ connection = $ this ->Trait -> getConnection ($ name );
8094 $ this ->assertInstanceof (Connection::class, $ connection );
8195 $ this ->assertEquals ('test ' , $ connection ->config ()['name ' ]);
8296 }
8397
8498 ConnectionManager::setConfig ('fake ' , ['url ' => 'mysql://root:password@localhost/my_database ' ]);
85- $ connection = $ this ->getConnection ('fake ' );
99+ $ connection = $ this ->Trait -> getConnection ('fake ' );
86100 $ this ->assertInstanceof (Connection::class, $ connection );
87101 $ this ->assertEquals ('fake ' , $ connection ->config ()['name ' ]);
88102
@@ -98,18 +112,18 @@ public function testGetConnection(): void
98112 public function testGetDriver (): void
99113 {
100114 foreach ([ConnectionManager::get ('test ' ), null ] as $ driver ) {
101- $ this ->assertInstanceof (Driver::class, $ this ->getDriver ($ driver ));
115+ $ this ->assertInstanceof (Driver::class, $ this ->Trait -> getDriver ($ driver ));
102116 }
103117
104118 //With a no existing driver
105119 $ connection = $ this ->getMockBuilder (Connection::class)
106- ->setMethods (['__debuginfo ' , 'getDriver ' ])
120+ ->onlyMethods (['__debuginfo ' , 'getDriver ' ])
107121 ->disableOriginalConstructor ()
108122 ->getMock ();
109123 $ connection ->method ('getDriver ' )->will ($ this ->returnValue (new Sqlserver ()));
110124 $ this ->expectException (InvalidArgumentException::class);
111125 $ this ->expectExceptionMessage ('The `Sqlserver` driver does not exist ' );
112- $ this ->getDriver ($ connection );
126+ $ this ->Trait -> getDriver ($ connection );
113127 }
114128
115129 /**
@@ -131,7 +145,7 @@ public function testGetExtension(): void
131145 'text ' => null ,
132146 '.txt ' => null ,
133147 ] as $ filename => $ expectedExtension ) {
134- $ this ->assertEquals ($ expectedExtension , $ this ->getExtension ($ filename ));
148+ $ this ->assertEquals ($ expectedExtension , $ this ->Trait -> getExtension ($ filename ));
135149 }
136150 }
137151
@@ -141,6 +155,6 @@ public function testGetExtension(): void
141155 */
142156 public function testGetValidCompressions (): void
143157 {
144- $ this ->assertNotEmpty ($ this ->getValidCompressions ());
158+ $ this ->assertNotEmpty ($ this ->Trait -> getValidCompressions ());
145159 }
146160}
0 commit comments