11
11
use ZendDiagnostics \Check \ExtensionLoaded ;
12
12
use ZendDiagnostics \Check \PhpVersion ;
13
13
use ZendDiagnostics \Check \ProcessRunning ;
14
- use ZendDiagnostics \Check \SecurityAdvisory ;
15
14
use ZendDiagnostics \Check \StreamWrapperExists ;
16
15
use ZendDiagnostics \Result \Success ;
16
+ use ZendDiagnosticsTest \TestAsset \Check \SecurityAdvisory ;
17
17
use ZendDiagnosticsTest \TestAsset \Check \AlwaysSuccess ;
18
18
19
19
class ChecksTest extends \PHPUnit_Framework_TestCase
@@ -416,33 +416,28 @@ public function testSecurityAdvisory()
416
416
}
417
417
418
418
$ secureComposerLock = __DIR__ . '/TestAsset/secure-composer.lock ' ;
419
- $ checker = new SecurityChecker ();
420
- $ check = new SecurityAdvisory ($ checker , $ secureComposerLock );
419
+ $ check = new SecurityAdvisory ($ secureComposerLock );
421
420
$ result = $ check ->check ();
422
421
$ this ->assertNotInstanceOf ('ZendDiagnostics\Result\Failure ' , $ result );
423
422
424
423
// check against non-existent lock file
425
- $ checker = new SecurityChecker ();
426
- $ check = new SecurityAdvisory ($ checker , __DIR__ . '/improbable-lock-file-99999999999.lock ' );
424
+ $ check = new SecurityAdvisory (__DIR__ . '/improbable-lock-file-99999999999.lock ' );
427
425
$ result = $ check ->check ();
428
426
$ this ->assertInstanceOf ('ZendDiagnostics\Result\Failure ' , $ result );
429
427
430
428
// check against unreadable lock file
431
429
$ tmpDir = sys_get_temp_dir ();
432
430
if (!is_dir ($ tmpDir ) || !is_writable ($ tmpDir )) {
433
431
$ this ->markTestSkipped ('Cannot access writable system temp dir to perform the test... ' );
434
-
435
432
return ;
436
433
}
437
434
$ unreadableFile = $ tmpDir . '/composer. ' . uniqid ('' , true ) . '.lock ' ;
438
435
if (!file_put_contents ($ unreadableFile , 'foo ' ) || !chmod ($ unreadableFile , 0000 )) {
439
436
$ this ->markTestSkipped ('Cannot create temporary file in system temp dir to perform the test... ' );
440
-
441
437
return ;
442
438
}
443
439
444
- $ checker = new SecurityChecker ();
445
- $ check = new SecurityAdvisory ($ checker , $ unreadableFile );
440
+ $ check = new SecurityAdvisory ($ unreadableFile );
446
441
$ result = $ check ->check ();
447
442
$ this ->assertInstanceOf ('ZendDiagnostics\Result\Failure ' , $ result );
448
443
@@ -463,7 +458,8 @@ public function testSecurityAdvisoryFailure()
463
458
->with ($ this ->equalTo ($ secureComposerLock ))
464
459
->will ($ this ->returnValue ('[{"a":1},{"b":2},{"c":3}] ' ));
465
460
466
- $ check = new SecurityAdvisory ($ checker , $ secureComposerLock );
461
+ $ check = new SecurityAdvisory ($ secureComposerLock );
462
+ $ check ->setSecurityChecker ($ checker );
467
463
$ result = $ check ->check ();
468
464
$ this ->assertInstanceOf ('ZendDiagnostics\Result\Failure ' , $ result );
469
465
}
@@ -479,7 +475,8 @@ public function testSecurityAdvisoryInvalidServerResponse()
479
475
->method ('check ' )
480
476
->with ($ this ->equalTo ($ secureComposerLock ))
481
477
->will ($ this ->returnValue ('404 error ' ));
482
- $ check = new SecurityAdvisory ($ checker , $ secureComposerLock );
478
+ $ check = new SecurityAdvisory ($ secureComposerLock );
479
+ $ check ->setSecurityChecker ($ checker );
483
480
$ result = $ check ->check ();
484
481
$ this ->assertInstanceOf ('ZendDiagnostics\Result\Warning ' , $ result );
485
482
@@ -495,7 +492,8 @@ public function testSecurityAdvisoryCheckerException()
495
492
->method ('check ' )
496
493
->with ($ this ->equalTo ($ secureComposerLock ))
497
494
->will ($ this ->throwException (new Exception ));
498
- $ check = new SecurityAdvisory ($ checker , $ secureComposerLock );
495
+ $ check = new SecurityAdvisory ($ secureComposerLock );
496
+ $ check ->setSecurityChecker ($ checker );
499
497
$ result = $ check ->check ();
500
498
$ this ->assertInstanceOf ('ZendDiagnostics\Result\Warning ' , $ result );
501
499
}
0 commit comments