Skip to content

Commit ed5faf4

Browse files
committed
Merge branch 'tests-refactor' of https://github.com/MGatner/CodeIgniter4 into tests-refactor
2 parents 2a17423 + f42c6ca commit ed5faf4

16 files changed

Lines changed: 89 additions & 114 deletions

File tree

tests/system/Autoloader/AutoloaderTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,11 @@ public function testMissingFile()
122122

123123
//--------------------------------------------------------------------
124124

125-
/**
126-
* @expectedException \InvalidArgumentException
127-
* @expectedExceptionMessage Config array must contain either the 'psr4' key or the 'classmap' key.
128-
*/
129125
public function testInitializeException()
130126
{
127+
$this->expectException('InvalidArgumentException');
128+
$this->expectExceptionMessage('Config array must contain either the 'psr4' key or the 'classmap' key.');
129+
131130
$config = new Autoload();
132131
$config->classmap = [];
133132
$config->psr4 = [];

tests/system/CLI/CLITest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,19 @@ public function testNewLine()
7676
CLI::newLine();
7777
}
7878

79-
/**
80-
* @expectedException RuntimeException
81-
* @expectedExceptionMessage Invalid foreground color: Foreground
82-
*/
8379
public function testColorExceptionForeground()
8480
{
81+
$this->expectException('RuntimeException');
82+
$this->expectExceptionMessage('Invalid foreground color: Foreground');
83+
8584
CLI::color('test', 'Foreground');
8685
}
8786

88-
/**
89-
* @expectedException RuntimeException
90-
* @expectedExceptionMessage Invalid background color: Background
91-
*/
9287
public function testColorExceptionBackground()
9388
{
89+
$this->expectException('RuntimeException');
90+
$this->expectException('Invalid background color: Background');
91+
9492
CLI::color('test', 'white', 'Background');
9593
}
9694

tests/system/Cache/CacheFactoryTest.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,41 @@ public function testNew()
3333
$this->assertInstanceOf(CacheFactory::class, $this->cacheFactory);
3434
}
3535

36-
/**
37-
* @expectedException \CodeIgniter\Cache\Exceptions\CacheException
38-
* @expectedExceptionMessage Cache config must have an array of $validHandlers.
39-
*/
4036
public function testGetHandlerExceptionCacheInvalidHandlers()
4137
{
38+
$this->expectException('CodeIgniter\Cache\Exceptions\CacheException');
39+
$this->expectExceptionMessage('Cache config must have an array of $validHandlers.');
40+
4241
$this->config->validHandlers = null;
4342

4443
$this->cacheFactory->getHandler($this->config);
4544
}
4645

47-
/**
48-
* @expectedException \CodeIgniter\Cache\Exceptions\CacheException
49-
* @expectedExceptionMessage Cache config must have a handler and backupHandler set.
50-
*/
5146
public function testGetHandlerExceptionCacheNoBackup()
5247
{
48+
$this->expectException('CodeIgniter\Cache\Exceptions\CacheException');
49+
$this->expectExceptionMessage('Cache config must have a handler and backupHandler set.');
50+
5351
$this->config->backupHandler = null;
5452

5553
$this->cacheFactory->getHandler($this->config);
5654
}
5755

58-
/**
59-
* @expectedException \CodeIgniter\Cache\Exceptions\CacheException
60-
* @expectedExceptionMessage Cache config must have a handler and backupHandler set.
61-
*/
6256
public function testGetHandlerExceptionCacheNoHandler()
6357
{
58+
$this->expectException('CodeIgniter\Cache\Exceptions\CacheException');
59+
$this->expectExceptionMessage('Cache config must have a handler and backupHandler set.');
60+
6461
$this->config->handler = null;
6562

6663
$this->cacheFactory->getHandler($this->config);
6764
}
6865

69-
/**
70-
* @expectedException \CodeIgniter\Cache\Exceptions\CacheException
71-
* @expectedExceptionMessage Cache config has an invalid handler or backup handler specified.
72-
*/
7366
public function testGetHandlerExceptionCacheHandlerNotFound()
7467
{
68+
$this->expectException('CodeIgniter\Cache\Exceptions\CacheException');
69+
$this->expectExceptionMessage('Cache config has an invalid handler or backup handler specified.');
70+
7571
unset($this->config->validHandlers[$this->config->handler]);
7672

7773
$this->cacheFactory->getHandler($this->config);

tests/system/Cache/Handlers/FileHandlerTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ public function testNew()
6767
$this->assertInstanceOf(FileHandler::class, $this->fileHandler);
6868
}
6969

70-
/**
71-
* @expectedException \CodeIgniter\Cache\Exceptions\CacheException
72-
*/
7370
public function testNewWithNonWritablePath()
7471
{
72+
$this->expectException('CodeIgniter\Cache\Exceptions\CacheException');
73+
7574
chmod($this->config->storePath, 0444);
7675
new FileHandler($this->config);
7776
}

tests/system/Database/Live/ModelTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,14 @@ public function testDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue
503503
} //--------------------------------------------------------------------
504504

505505
/**
506-
* @expectedException \CodeIgniter\Database\Exceptions\DatabaseException
507-
* @expectedExceptionMessage Deletes are not allowed unless they contain a "where" or "like" clause.
508506
* @dataProvider emptyPkValues
509507
* @return void
510508
*/
511509
public function testThrowExceptionWhenSoftDeleteParamIsEmptyValue($emptyValue)
512510
{
511+
$this->expectException('CodeIgniter\Database\Exceptions\DatabaseException');
512+
$this->expectExceptionMessage('Deletes are not allowed unless they contain a "where" or "like" clause.');
513+
513514
$model = new UserModel();
514515
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]);
515516
$model->delete($emptyValue);
@@ -518,13 +519,14 @@ public function testThrowExceptionWhenSoftDeleteParamIsEmptyValue($emptyValue)
518519
//--------------------------------------------------------------------
519520

520521
/**
521-
* @expectedException \CodeIgniter\Database\Exceptions\DatabaseException
522-
* @expectedExceptionMessage Deletes are not allowed unless they contain a "where" or "like" clause.
523522
* @dataProvider emptyPkValues
524523
* @return void
525524
*/
526525
public function testDontDeleteRowsWhenSoftDeleteParamIsEmpty($emptyValue)
527526
{
527+
$this->expectException('CodeIgniter\Database\Exceptions\DatabaseException');
528+
$this->expectExceptionMessage('Deletes are not allowed unless they contain a "where" or "like" clause.');
529+
528530
$model = new UserModel();
529531
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]);
530532
$model->delete($emptyValue);
@@ -1262,12 +1264,11 @@ public function testValidationIncludingErrors()
12621264

12631265
//--------------------------------------------------------------------
12641266

1265-
/**
1266-
* @expectedException \CodeIgniter\Exceptions\ModelException
1267-
* @expectedExceptionMessage `Tests\Support\Models\UserModel` model class does not specify a Primary Key.
1268-
*/
12691267
public function testThrowsWithNoPrimaryKey()
12701268
{
1269+
$this->expectException('CodeIgniter\Exceptions\ModelException');
1270+
$this->expectExceptionMessage('`Tests\Support\Models\UserModel` model class does not specify a Primary Key.');
1271+
12711272
$model = new UserModel();
12721273
$this->setPrivateProperty($model, 'primaryKey', '');
12731274

@@ -1276,12 +1277,11 @@ public function testThrowsWithNoPrimaryKey()
12761277

12771278
//--------------------------------------------------------------------
12781279

1279-
/**
1280-
* @expectedException \CodeIgniter\Exceptions\ModelException
1281-
* @expectedExceptionMessage `Tests\Support\Models\UserModel` model class does not have a valid dateFormat.
1282-
*/
12831280
public function testThrowsWithNoDateFormat()
12841281
{
1282+
$this->expectException('CodeIgniter\Exceptions\ModelException');
1283+
$this->expectExceptionMessage('`Tests\Support\Models\UserModel` model class does not have a valid dateFormat.');
1284+
12851285
$model = new UserModel();
12861286
$this->setPrivateProperty($model, 'dateFormat', '');
12871287

tests/system/Database/Live/SQLite/AlterTableTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ public function tearDown(): void
4848
$this->forge->dropTable('foo_fk', true);
4949
}
5050

51-
/**
52-
* @expectedException \CodeIgniter\Database\Exceptions\DataException
53-
* @expectedExceptionMessage Table `foo` was not found in the current database.
54-
*/
5551
public function testFromTableThrowsOnNoTable()
5652
{
53+
$this->expectException('CodeIgniter\Database\Exceptions\DataException');
54+
$this->expectExceptionMessage('Table `foo` was not found in the current database.');
55+
5756
$this->table->fromTable('foo');
5857
}
5958

tests/system/Database/Migrations/MigrationRunnerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,11 @@ public function testFindMigrationsSuccessTimestamp()
204204
$this->assertEquals($mig2, array_shift($migrations));
205205
}
206206

207-
/**
208-
* @expectedException \CodeIgniter\Exceptions\ConfigException
209-
* @expectedExceptionMessage Migrations have been loaded but are disabled or setup incorrectly.
210-
*/
211207
public function testMigrationThrowsDisabledException()
212208
{
209+
$this->expectException('CodeIgniter\Exceptions\ConfigException');
210+
$this->expectExceptionMessage('Migrations have been loaded but are disabled or setup incorrectly.');
211+
213212
$config = $this->config;
214213
$config->enabled = false;
215214
$runner = new MigrationRunner($config);

tests/system/Debug/TimerTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ public function testElapsedTimeGivesSameResultAsTimersArray()
7676

7777
//--------------------------------------------------------------------
7878

79-
/**
80-
* @expectedException RunTimeException
81-
*/
8279
public function testThrowsExceptionStoppingNonTimer()
8380
{
81+
$this->expectException('RunTimeException');
82+
8483
$timer = new Timer();
8584

8685
$timer->stop('test1');

tests/system/Encryption/EncryptionTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public function testConstructor()
4141

4242
/**
4343
* Covers behavior with invalid parameters
44-
*
45-
* @expectedException \CodeIgniter\Encryption\Exceptions\EncryptionException
4644
*/
4745
public function testBadDriver()
4846
{
47+
$this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException');
48+
4949
// ask for a bad driver
5050
$config = new EncryptionConfig();
5151
$config->driver = 'Bogus';
@@ -56,11 +56,11 @@ public function testBadDriver()
5656

5757
/**
5858
* Covers behavior with invalid parameters
59-
*
60-
* @expectedException \CodeIgniter\Encryption\Exceptions\EncryptionException
6159
*/
6260
public function testMissingDriver()
6361
{
62+
$this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException');
63+
6464
// ask for a bad driver
6565
$config = new EncryptionConfig();
6666
$config->driver = '';
@@ -90,11 +90,10 @@ public function testServiceSuccess()
9090
$this->assertInstanceOf(EncrypterInterface::class, $encrypter);
9191
}
9292

93-
/**
94-
* @expectedException \CodeIgniter\Encryption\Exceptions\EncryptionException
95-
*/
9693
public function testServiceFailure()
9794
{
95+
$this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException');
96+
9897
// ask for a bad driver
9998
$config = new EncryptionConfig();
10099
$config->driver = 'Kazoo';
@@ -103,11 +102,10 @@ public function testServiceFailure()
103102
$encrypter = Services::encrypter($config);
104103
}
105104

106-
/**
107-
* @expectedException \CodeIgniter\Encryption\Exceptions\EncryptionException
108-
*/
109105
public function testServiceWithoutKey()
110106
{
107+
$this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException');
108+
111109
$encrypter = Services::encrypter();
112110
}
113111

tests/system/Encryption/OpenSSLHandlerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ public function testSimple()
5757

5858
/**
5959
* Starter key needed
60-
*
61-
* @expectedException \CodeIgniter\Encryption\Exceptions\EncryptionException
6260
*/
6361
public function testWithoutKey()
6462
{
63+
$this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException');
64+
6565
$encrypter = new \CodeIgniter\Encryption\Handlers\OpenSSLHandler();
6666
$message1 = 'This is a plain-text message.';
6767
$encrypter->encrypt($message1);
@@ -78,11 +78,11 @@ public function testWithKeyString()
7878

7979
/**
8080
* Authentication will fail decrypting with the wrong key
81-
*
82-
* @expectedException \CodeIgniter\Encryption\Exceptions\EncryptionException
8381
*/
8482
public function testWithWrongKeyString()
8583
{
84+
$this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException');
85+
8686
$key1 = 'abracadabra';
8787
$encrypter = new \CodeIgniter\Encryption\Handlers\OpenSSLHandler();
8888
$message1 = 'This is a plain-text message.';
@@ -103,11 +103,11 @@ public function testWithKeyArray()
103103

104104
/**
105105
* Authentication will fail decrypting with the wrong key
106-
*
107-
* @expectedException \CodeIgniter\Encryption\Exceptions\EncryptionException
108106
*/
109107
public function testWithWrongKeyArray()
110108
{
109+
$this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException');
110+
111111
$key1 = 'abracadabra';
112112
$encrypter = new \CodeIgniter\Encryption\Handlers\OpenSSLHandler();
113113
$message1 = 'This is a plain-text message.';

0 commit comments

Comments
 (0)