Skip to content

Commit 3d12104

Browse files
authored
Remove expectedException annotations (simplesamlphp#1113)
1 parent 46f5239 commit 3d12104

30 files changed

Lines changed: 141 additions & 175 deletions

TESTING.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ throws an exception in a specific situation:
4040
```php
4141
/**
4242
* Test SimpleSAML\Utils\HTTP::addURLParameters().
43-
*
44-
* @expectedException \InvalidArgumentException
4543
*/
4644
public function testAddURLParametersInvalidParameters() {
45+
$this->expectException(ExpectedException::class);
4746
```
4847

49-
Refer to [the `phpunit 4.8` documentation](https://phpunit.de/manual/4.8/en/installation.html)
50-
for more information on how to write tests. We currently use the `phpunit 4.8`
51-
since it is the last version to support php 5.3.
48+
Refer to [the `phpunit 5.7` documentation](https://phpunit.de/manual/5.7/en/installation.html)
49+
for more information on how to write tests. We currently use the `phpunit 5.7`
50+
since it is the last version to support php 5.6.
5251

5352
Once you have implemented your tests, you can run them locally. First,
5453
make sure the `config` directory is **not** in the root of your
@@ -59,7 +58,7 @@ you have `phpunit` installed and run:
5958
phpunit -c ./phpunit.xml
6059
```
6160

62-
If your default version of `phpunit` is more recent than 4.8, you can run
61+
If your default version of `phpunit` is more recent than 5.7, you can run
6362
the old version installed by composer
6463

6564
```sh

tests/lib/SimpleSAML/ConfigurationTest.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace SimpleSAML\Test;
44

5-
use \SimpleSAML\Configuration;
5+
use SimpleSAML\Configuration;
6+
use SimpleSAML\Error\CriticalConfigurationError;
67

78
/**
89
* Tests for \SimpleSAML\Configuration
@@ -20,10 +21,10 @@ public function testGetVersion()
2021

2122
/**
2223
* Test that the default instance fails to load even if we previously loaded another instance.
23-
* @expectedException \SimpleSAML\Error\CriticalConfigurationError
2424
*/
2525
public function testLoadDefaultInstance()
2626
{
27+
$this->expectException(CriticalConfigurationError::class);
2728
Configuration::loadFromArray(['key' => 'value'], '', 'dummy');
2829
Configuration::getInstance();
2930
}
@@ -70,10 +71,10 @@ public function testGetValue()
7071

7172
/**
7273
* Test \SimpleSAML\Configuration::getValue(), REQUIRED_OPTION flag.
73-
* @expectedException Exception
7474
*/
7575
public function testGetValueRequired()
7676
{
77+
$this->expectException(\Exception::class);
7778
$c = Configuration::loadFromArray([]);
7879
$c->getValue('missing', Configuration::REQUIRED_OPTION);
7980
}
@@ -239,20 +240,20 @@ public function testGetBoolean()
239240

240241
/**
241242
* Test \SimpleSAML\Configuration::getBoolean() missing option
242-
* @expectedException Exception
243243
*/
244244
public function testGetBooleanMissing()
245245
{
246+
$this->expectException(\Exception::class);
246247
$c = Configuration::loadFromArray([]);
247248
$c->getBoolean('missing_opt');
248249
}
249250

250251
/**
251252
* Test \SimpleSAML\Configuration::getBoolean() wrong option
252-
* @expectedException Exception
253253
*/
254254
public function testGetBooleanWrong()
255255
{
256+
$this->expectException(\Exception::class);
256257
$c = Configuration::loadFromArray([
257258
'wrong' => 'true',
258259
]);
@@ -273,20 +274,20 @@ public function testGetString()
273274

274275
/**
275276
* Test \SimpleSAML\Configuration::getString() missing option
276-
* @expectedException Exception
277277
*/
278278
public function testGetStringMissing()
279279
{
280+
$this->expectException(\Exception::class);
280281
$c = Configuration::loadFromArray([]);
281282
$c->getString('missing_opt');
282283
}
283284

284285
/**
285286
* Test \SimpleSAML\Configuration::getString() wrong option
286-
* @expectedException Exception
287287
*/
288288
public function testGetStringWrong()
289289
{
290+
$this->expectException(\Exception::class);
290291
$c = Configuration::loadFromArray([
291292
'wrong' => false,
292293
]);
@@ -307,20 +308,20 @@ public function testGetInteger()
307308

308309
/**
309310
* Test \SimpleSAML\Configuration::getInteger() missing option
310-
* @expectedException Exception
311311
*/
312312
public function testGetIntegerMissing()
313313
{
314+
$this->expectException(\Exception::class);
314315
$c = Configuration::loadFromArray([]);
315316
$c->getInteger('missing_opt');
316317
}
317318

318319
/**
319320
* Test \SimpleSAML\Configuration::getInteger() wrong option
320-
* @expectedException Exception
321321
*/
322322
public function testGetIntegerWrong()
323323
{
324+
$this->expectException(\Exception::class);
324325
$c = Configuration::loadFromArray([
325326
'wrong' => '42',
326327
]);
@@ -341,10 +342,10 @@ public function testGetIntegerRange()
341342

342343
/**
343344
* Test \SimpleSAML\Configuration::getIntegerRange() below limit
344-
* @expectedException Exception
345345
*/
346346
public function testGetIntegerRangeBelow()
347347
{
348+
$this->expectException(\Exception::class);
348349
$c = Configuration::loadFromArray([
349350
'int_opt' => 9,
350351
]);
@@ -353,10 +354,10 @@ public function testGetIntegerRangeBelow()
353354

354355
/**
355356
* Test \SimpleSAML\Configuration::getIntegerRange() above limit
356-
* @expectedException Exception
357357
*/
358358
public function testGetIntegerRangeAbove()
359359
{
360+
$this->expectException(\Exception::class);
360361
$c = Configuration::loadFromArray([
361362
'int_opt' => 101,
362363
]);
@@ -377,10 +378,10 @@ public function testGetValueValidate()
377378

378379
/**
379380
* Test \SimpleSAML\Configuration::getValueValidate() wrong option
380-
* @expectedException Exception
381381
*/
382382
public function testGetValueValidateWrong()
383383
{
384+
$this->expectException(\Exception::class);
384385
$c = Configuration::loadFromArray([
385386
'opt' => 'd',
386387
]);
@@ -401,10 +402,10 @@ public function testGetArray()
401402

402403
/**
403404
* Test \SimpleSAML\Configuration::getArray() wrong option
404-
* @expectedException Exception
405405
*/
406406
public function testGetArrayWrong()
407407
{
408+
$this->expectException(\Exception::class);
408409
$c = Configuration::loadFromArray([
409410
'opt' => 'not_an_array',
410411
]);
@@ -444,10 +445,10 @@ public function testGetArrayizeString()
444445
/**
445446
* Test \SimpleSAML\Configuration::getArrayizeString() option
446447
* with an array that contains something that isn't a string.
447-
* @expectedException Exception
448448
*/
449449
public function testGetArrayizeStringWrongValue()
450450
{
451+
$this->expectException(\Exception::class);
451452
$c = Configuration::loadFromArray([
452453
'opt' => ['a', 'b', 42],
453454
]);
@@ -470,10 +471,10 @@ public function testGetConfigItem()
470471

471472
/**
472473
* Test \SimpleSAML\Configuration::getConfigItem() wrong option
473-
* @expectedException Exception
474474
*/
475475
public function testGetConfigItemWrong()
476476
{
477+
$this->expectException(\Exception::class);
477478
$c = Configuration::loadFromArray([
478479
'opt' => 'not_an_array',
479480
]);
@@ -503,10 +504,10 @@ public function testGetConfigList()
503504

504505
/**
505506
* Test \SimpleSAML\Configuration::getConfigList() wrong option
506-
* @expectedException Exception
507507
*/
508508
public function testGetConfigListWrong()
509509
{
510+
$this->expectException(\Exception::class);
510511
$c = Configuration::loadFromArray([
511512
'opt' => 'not_an_array',
512513
]);
@@ -516,10 +517,10 @@ public function testGetConfigListWrong()
516517

517518
/**
518519
* Test \SimpleSAML\Configuration::getConfigList() with an array of wrong options.
519-
* @expectedException Exception
520520
*/
521521
public function testGetConfigListWrongArrayValues()
522522
{
523+
$this->expectException(\Exception::class);
523524
$c = Configuration::loadFromArray([
524525
'opts' => [
525526
'a',
@@ -895,10 +896,10 @@ public function testGetLocalizedString()
895896

896897
/**
897898
* Test \SimpleSAML\Configuration::getLocalizedString() not array nor simple string
898-
* @expectedException Exception
899899
*/
900900
public function testGetLocalizedStringNotArray()
901901
{
902+
$this->expectException(\Exception::class);
902903
$c = Configuration::loadFromArray([
903904
'opt' => 42,
904905
]);
@@ -907,10 +908,10 @@ public function testGetLocalizedStringNotArray()
907908

908909
/**
909910
* Test \SimpleSAML\Configuration::getLocalizedString() not string key
910-
* @expectedException Exception
911911
*/
912912
public function testGetLocalizedStringNotStringKey()
913913
{
914+
$this->expectException(\Exception::class);
914915
$c = Configuration::loadFromArray([
915916
'opt' => [42 => 'text'],
916917
]);
@@ -919,10 +920,10 @@ public function testGetLocalizedStringNotStringKey()
919920

920921
/**
921922
* Test \SimpleSAML\Configuration::getLocalizedString() not string value
922-
* @expectedException Exception
923923
*/
924924
public function testGetLocalizedStringNotStringValue()
925925
{
926+
$this->expectException(\Exception::class);
926927
$c = Configuration::loadFromArray([
927928
'opt' => ['en' => 42],
928929
]);
@@ -931,10 +932,10 @@ public function testGetLocalizedStringNotStringValue()
931932

932933
/**
933934
* Test \SimpleSAML\Configuration::getConfig() nonexistent file
934-
* @expectedException Exception
935935
*/
936936
public function testGetConfigNonexistentFile()
937937
{
938+
$this->expectException(\Exception::class);
938939
Configuration::getConfig('nonexistent-nopreload.php');
939940
}
940941

tests/lib/SimpleSAML/DatabaseTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ public function setUp()
7979
* @covers SimpleSAML\Database::generateInstanceId
8080
* @covers SimpleSAML\Database::__construct
8181
* @covers SimpleSAML\Database::connect
82-
* @expectedException Exception
8382
* @test
8483
*/
8584
public function connectionFailure()
8685
{
86+
$this->expectException(\Exception::class);
8787
$config = [
8888
'database.dsn' => 'mysql:host=localhost;dbname=saml',
8989
'database.username' => 'notauser',
@@ -263,11 +263,11 @@ public function querying()
263263
/**
264264
* @covers SimpleSAML\Database::read
265265
* @covers SimpleSAML\Database::query
266-
* @expectedException Exception
267266
* @test
268267
*/
269268
public function readFailure()
270269
{
270+
$this->expectException(\Exception::class);
271271
$table = $this->db->applyPrefix("sspdbt");
272272
$this->assertEquals($this->config->getString('database.prefix')."sspdbt", $table);
273273

@@ -278,11 +278,11 @@ public function readFailure()
278278
/**
279279
* @covers SimpleSAML\Database::write
280280
* @covers SimpleSAML\Database::exec
281-
* @expectedException Exception
282281
* @test
283282
*/
284283
public function noSuchTable()
285284
{
285+
$this->expectException(\Exception::class);
286286
$this->db->write("DROP TABLE phpunit_nonexistent", false);
287287
}
288288

tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ class MetaDataStorageSourceTest extends \PHPUnit\Framework\TestCase
1010
{
1111
/**
1212
* Test \SimpleSAML\Metadata\MetaDataStorageSourceTest::getConfig XML bad source
13-
* @expectedException \Exception
1413
*/
1514
public function testBadXMLSource()
1615
{
16+
$this->expectException(\Exception::class);
1717
\SimpleSAML\Metadata\MetaDataStorageSource::getSource(["type"=>"xml", "foo"=>"baa"]);
1818
}
1919

2020
/**
2121
* Test \SimpleSAML\Metadata\MetaDataStorageSourceTest::getConfig invalid static XML source
22-
* @expectedException Exception
2322
*/
2423
public function testInvalidStaticXMLSource()
2524
{
25+
$this->expectException(\Exception::class);
2626
$strTestXML = "
2727
<EntityDescriptor ID=\"_12345678-90ab-cdef-1234-567890abcdef\" entityID=\"https://saml.idp/entityid\" xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\">
2828
</EntityDescriptor>

tests/lib/SimpleSAML/ModuleTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,32 @@ public function testGetModules()
6565
* Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if we are not asking
6666
* for a class inside a module (that is, there is no colon separating the name of the module and the name of the
6767
* class).
68-
*
69-
* @expectedException \Exception
7068
*/
7169
public function testResolveClassNoModule()
7270
{
71+
$this->expectException(\Exception::class);
7372
Module::resolveClass('nomodule', '');
7473
}
7574

7675

7776
/**
7877
* Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if the class we are
7978
* asking for cannot be found.
80-
*
81-
* @expectedException \Exception
8279
*/
8380
public function testResolveClassNotFound()
8481
{
82+
$this->expectException(\Exception::class);
8583
Module::resolveClass('core:Missing', '');
8684
}
8785

8886

8987
/**
9088
* Test for SimpleSAML\Module::resolveClass(). It will make sure that an exception is thrown if the class we are
9189
* asking for can be resolved, but does not extend a given class.
92-
*
93-
* @expectedException \Exception
9490
*/
9591
public function testResolveClassNotSubclass()
9692
{
93+
$this->expectException(\Exception::class);
9794
Module::resolveClass('core:PHP', 'Auth_Process', '\Exception');
9895
}
9996

0 commit comments

Comments
 (0)