From ac270843febebd350e820e45498c0c5ca2d5f26c Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 4 Aug 2024 23:00:05 +0200 Subject: [PATCH] Fix unit tests --- .../src/TestCase/AuthSource/Ldap/LdapBindTest.php | 2 +- tests/src/TestCase/AuthSource/NegotiateTest.php | 12 ++++++------ tests/src/TestCase/CertificatesTest.php | 2 +- tests/src/TestCase/Network/ConnectUriTest.php | 15 +++++++++++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/src/TestCase/AuthSource/Ldap/LdapBindTest.php b/tests/src/TestCase/AuthSource/Ldap/LdapBindTest.php index 792248d..bb32c92 100644 --- a/tests/src/TestCase/AuthSource/Ldap/LdapBindTest.php +++ b/tests/src/TestCase/AuthSource/Ldap/LdapBindTest.php @@ -25,7 +25,7 @@ public function testBindSuccesful(): void $connectionMock = $this->getMockBuilder(Ldap::class)->onlyMethods( ['bind'], )->disableOriginalConstructor()->getMock(); - $connectionMock->expects($this->once())->method('bind')->willReturn(true); + $connectionMock->expects($this->once())->method('bind'); $confTest = new TestCase\AuthSource\Ldap\Bind( new TestData([ 'authSourceData' => Configuration::loadFromArray($authSourceData), diff --git a/tests/src/TestCase/AuthSource/NegotiateTest.php b/tests/src/TestCase/AuthSource/NegotiateTest.php index fcb2afe..3ab6cf9 100644 --- a/tests/src/TestCase/AuthSource/NegotiateTest.php +++ b/tests/src/TestCase/AuthSource/NegotiateTest.php @@ -49,10 +49,10 @@ public function testNegotiateSuccess(): void $KRB5NegotiateAuthMock = $this->getMockBuilder(KRB5NegotiateAuth::class)->onlyMethods( ['doAuthentication', 'getAuthenticatedUser'], )->disableOriginalConstructor()->getMock(); - $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->will($this->returnValue(true)); - $KRB5NegotiateAuthMock->expects($this->any())->method('getAuthenticatedUser')->will( - $this->returnValue('testuser@example.org'), - ); + $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->willReturn(true); + $KRB5NegotiateAuthMock->expects($this->any()) + ->method('getAuthenticatedUser') + ->willReturn('testuser@example.org'); $testData = new TestData([ 'handle' => $KRB5NegotiateAuthMock, ]); @@ -67,7 +67,7 @@ public function testNegotiateNoAuthorzation(): void $KRB5NegotiateAuthMock = $this->getMockBuilder(KRB5NegotiateAuth::class)->onlyMethods( ['doAuthentication', 'getAuthenticatedUser'], )->disableOriginalConstructor()->getMock(); - $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->will($this->returnValue(false)); + $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->willReturn(false); $testData = new TestData([ 'handle' => $KRB5NegotiateAuthMock, ]); @@ -82,7 +82,7 @@ public function testNegotiateError(): void $KRB5NegotiateAuthMock = $this->getMockBuilder(KRB5NegotiateAuth::class)->onlyMethods( ['doAuthentication', 'getAuthenticatedUser'], )->disableOriginalConstructor()->getMock(); - $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->will($this->returnValue(false)); + $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->willReturn(false); $testData = new TestData([ 'handle' => $KRB5NegotiateAuthMock, 'authorization' => 'test', diff --git a/tests/src/TestCase/CertificatesTest.php b/tests/src/TestCase/CertificatesTest.php index d3b2159..046cf81 100644 --- a/tests/src/TestCase/CertificatesTest.php +++ b/tests/src/TestCase/CertificatesTest.php @@ -18,7 +18,7 @@ class TestCertificatesTest extends \PHPUnit\Framework\TestCase public static function setUpBeforeClass(): void { - self::$certdir = getcwd() . '/vendor/simplesamlphp/xml-security/tests/resources/certificates/'; + self::$certdir = getcwd() . '/vendor/simplesamlphp/xml-security/resources/certificates/'; } public function testCertExpired(): void diff --git a/tests/src/TestCase/Network/ConnectUriTest.php b/tests/src/TestCase/Network/ConnectUriTest.php index 0cbf57b..30be27e 100644 --- a/tests/src/TestCase/Network/ConnectUriTest.php +++ b/tests/src/TestCase/Network/ConnectUriTest.php @@ -8,6 +8,8 @@ use SimpleSAML\Module\monitor\TestCase; use SimpleSAML\Module\monitor\TestData; +use function gethostbyname; +use function sprintf; use function stream_context_create; /** @@ -15,10 +17,18 @@ */ class TestConnectUriTest extends \PHPUnit\Framework\TestCase { + protected string $host; + + public static function setUpBeforeClass(): void + { + self::$host = gethostbyname('packagist.org'); + } + public function testConnectUriOK(): void { $testData = new TestData([ - 'uri' => 'ssl://127.0.0.1:443', + 'uri' => sprintf('ssl://%s:443', self::$host), + 'timeout' => 3, 'context' => stream_context_create([ "ssl" => [ "capture_peer_cert" => true, @@ -35,7 +45,8 @@ public function testConnectUriOK(): void public function testConnectUriFailed(): void { $testData = new TestData([ - 'uri' => 'ssl://127.0.0.1:442', + 'uri' => sprintf('ssl://%s:442', self::$host), + 'timeout' => 3, ]); $connectionTest = new TestCase\Network\ConnectUri($testData); $testResult = $connectionTest->getTestResult();