From bbda8e4a40913ae42299141e74e22cadbfe45bcc Mon Sep 17 00:00:00 2001 From: Chad Sikorra Date: Sun, 30 Nov 2025 12:35:47 -0500 Subject: [PATCH 1/2] Fix various return types, test assertions, and other static analysis-related issues. --- src/FreeDSx/Ldap/Entry/Entries.php | 14 +----- src/FreeDSx/Ldap/Entry/Entry.php | 2 +- tests/bin/ldapserver.php | 5 +- tests/integration/LdapClientTest.php | 17 +++---- tests/integration/LdapProxyTest.php | 4 +- tests/integration/LdapServerTest.php | 18 +++---- tests/integration/LdapTestCase.php | 12 ++--- .../integration/Search/RangeRetrievalTest.php | 3 +- .../activedirectory/generate-ldif.php | 4 +- tests/unit/ContainerTest.php | 3 ++ tests/unit/Entry/EntryTest.php | 2 +- tests/unit/LdapClientTest.php | 48 +++++++++---------- .../Operation/Request/AbandonRequestTest.php | 5 -- .../Operation/Request/SearchRequestTest.php | 1 + .../Request/SimpleBindRequestTest.php | 12 ++--- .../Operation/Response/AddResponseTest.php | 2 +- .../ClientSaslBindHandlerTest.php | 2 + tests/unit/Protocol/Queue/ClientQueueTest.php | 10 +--- tests/unit/Protocol/Queue/ServerQueueTest.php | 13 ++--- .../unit/Protocol/ServerAuthorizationTest.php | 3 ++ .../ServerRootDseHandlerTest.php | 6 +-- tests/unit/Search/DirSyncTest.php | 9 ++-- tests/unit/Search/RangeRetrievalTest.php | 8 ++-- tests/unit/Server/RequestHistoryTest.php | 5 +- .../unit/Server/ServerProtocolFactoryTest.php | 5 +- tests/unit/Server/SocketServerFactoryTest.php | 15 +++--- 26 files changed, 95 insertions(+), 133 deletions(-) diff --git a/src/FreeDSx/Ldap/Entry/Entries.php b/src/FreeDSx/Ldap/Entry/Entries.php index d744d769..3c1dee2c 100644 --- a/src/FreeDSx/Ldap/Entry/Entries.php +++ b/src/FreeDSx/Ldap/Entry/Entries.php @@ -31,27 +31,19 @@ * @author Chad Sikorra * * @implements IteratorAggregate - * @template T of Entry */ class Entries implements Countable, IteratorAggregate { /** - * @var array + * @var array */ private array $entries; - /** - * @param T ...$entries - */ public function __construct(Entry ...$entries) { $this->entries = $entries; } - /** - * @param T ...$entries - * @return $this - */ public function add(Entry ...$entries): self { $this->entries = array_merge($this->entries, $entries); @@ -59,10 +51,6 @@ public function add(Entry ...$entries): self return $this; } - /** - * @param T ...$entries - * @return $this - */ public function remove(Entry ...$entries): self { foreach ($entries as $entry) { diff --git a/src/FreeDSx/Ldap/Entry/Entry.php b/src/FreeDSx/Ldap/Entry/Entry.php index 027ca0b4..a9a53341 100644 --- a/src/FreeDSx/Ldap/Entry/Entry.php +++ b/src/FreeDSx/Ldap/Entry/Entry.php @@ -299,7 +299,7 @@ public static function create( /** * Construct an entry from an associative array. * - * @param array> $attributes + * @param array> $attributes */ public static function fromArray( Dn|Stringable|string $dn, diff --git a/tests/bin/ldapserver.php b/tests/bin/ldapserver.php index 9e98426a..af532732 100644 --- a/tests/bin/ldapserver.php +++ b/tests/bin/ldapserver.php @@ -83,7 +83,10 @@ private function logRequest( class LdapServerRequestHandler extends GenericRequestHandler { - private $users = [ + /** + * @var array + */ + private array $users = [ 'cn=user,dc=foo,dc=bar' => '12345', ]; diff --git a/tests/integration/LdapClientTest.php b/tests/integration/LdapClientTest.php index 7502db6f..7d04db8c 100644 --- a/tests/integration/LdapClientTest.php +++ b/tests/integration/LdapClientTest.php @@ -51,8 +51,8 @@ public function tearDown(): void public function testUsernamePasswordBind(): void { $response = $this->client->bind( - $_ENV['LDAP_USERNAME'], - $_ENV['LDAP_PASSWORD'] + (string) getenv('LDAP_USERNAME'), + (string) getenv('LDAP_PASSWORD'), )->getResponse(); $this->assertInstanceOf( @@ -309,10 +309,6 @@ public function testRenameOperation(): void ModifyDnResponse::class, $result->getResponse() ); - $this->assertInstanceOf( - Entry::class, - $entry - ); $this->assertSame( ['Arleen Sevigny-Foo'], $entry->get('cn')?->getValues() @@ -420,10 +416,6 @@ public function testSubSearchOperation(): void Filters::raw('(&(objectClass=inetOrgPerson)(cn=A*))') )); - $this->assertInstanceOf( - Entries::class, - $entries - ); $this->assertCount( 843, $entries, @@ -561,12 +553,15 @@ public function testUseSslIgnoreCertValidation(): void $this->assertTrue($this->client->isConnected()); } + /** + * @return array + */ protected function getSaslOptions(): array { if ($this->isActiveDirectory()) { return [ 'username' => 'admin', - 'password' => $_ENV['LDAP_PASSWORD'], + 'password' => (string) getenv('LDAP_PASSWORD'), 'host' => 'ADDC3.example.com' ]; } else { diff --git a/tests/integration/LdapProxyTest.php b/tests/integration/LdapProxyTest.php index dbb9ef40..ef9506e9 100644 --- a/tests/integration/LdapProxyTest.php +++ b/tests/integration/LdapProxyTest.php @@ -76,8 +76,8 @@ public function testItCanHandlePaging(): void protected function authenticate(): void { $this->ldapClient()->bind( - $_ENV['LDAP_USERNAME'], - $_ENV['LDAP_PASSWORD'] + (string) getenv('LDAP_USERNAME'), + (string) getenv('LDAP_PASSWORD'), ); } } diff --git a/tests/integration/LdapServerTest.php b/tests/integration/LdapServerTest.php index 7efeb249..3d4fd879 100644 --- a/tests/integration/LdapServerTest.php +++ b/tests/integration/LdapServerTest.php @@ -33,13 +33,12 @@ public function setUp(): void public function testItCanBind(): void { - $response = $this->ldapClient()->bind( + $this->ldapClient()->bind( 'cn=user,dc=foo,dc=bar', '12345' ); $output = $this->waitForServerOutput('---bind---'); - $this->assertNotNull($response); $this->assertStringContainsString( 'username => cn=user,dc=foo,dc=bar', $output @@ -69,7 +68,7 @@ public function testItRejectsBindWithIncorrectCredentials(): void public function testItPerformsAnAdd(): void { $this->authenticate(); - $response = $this->ldapClient()->create(Entry::fromArray( + $this->ldapClient()->create(Entry::fromArray( 'cn=meh,dc=foo,dc=bar', [ 'foo' => 'bar', @@ -77,7 +76,6 @@ public function testItPerformsAnAdd(): void )); $output = $this->waitForServerOutput('---add---'); - $this->assertNotNull($response); $this->assertStringContainsString( 'dn => cn=meh,dc=foo,dc=bar', $output @@ -91,10 +89,9 @@ public function testItPerformsAnAdd(): void public function testItPerformsDelete(): void { $this->authenticate(); - $response = $this->ldapClient()->delete('cn=meh,dc=foo,dc=bar'); + $this->ldapClient()->delete('cn=meh,dc=foo,dc=bar'); $output = $this->waitForServerOutput('---delete---'); - $this->assertNotNull($response); $this->assertStringContainsString( 'dn => cn=meh,dc=foo,dc=bar', $output @@ -119,10 +116,9 @@ public function testItPerformsModify(): void $entry->set('surname', 'LastName'); $entry->reset('phone'); - $response = $this->ldapClient()->update($entry); + $this->ldapClient()->update($entry); $output = $this->waitForServerOutput('---modify---'); - $this->assertNotNull($response); $this->assertStringContainsString( 'dn => cn=meh,dc=foo,dc=bar', $output @@ -155,14 +151,13 @@ public function testItCanPerformCompare(): void { $this->authenticate(); - $response = $this->ldapClient()->compare( + $this->ldapClient()->compare( 'cn=meh,dc=foo,dc=bar', 'foo', 'bar' ); $output = $this->waitForServerOutput('---compare---'); - $this->assertNotNull($response); $this->assertStringContainsString( 'dn => cn=meh,dc=foo,dc=bar', $output @@ -181,13 +176,12 @@ public function testItCanModifyDn(): void { $this->authenticate(); - $response = $this->ldapClient()->move( + $this->ldapClient()->move( 'cn=meh,dc=foo,dc=bar', 'cn=bleh,dc=foo,dc=bar' ); $output = $this->waitForServerOutput('---modify-dn---'); - $this->assertNotNull($response); $this->assertStringContainsString( 'dn => cn=meh,dc=foo,dc=bar', $output diff --git a/tests/integration/LdapTestCase.php b/tests/integration/LdapTestCase.php index f2cd7bb7..a7d021e5 100644 --- a/tests/integration/LdapTestCase.php +++ b/tests/integration/LdapTestCase.php @@ -25,14 +25,14 @@ class LdapTestCase extends TestCase protected function makeOptions(): ClientOptions { return (new ClientOptions()) - ->setBaseDn((string) $_ENV['LDAP_BASE_DN']) - ->setServers([(string) $_ENV['LDAP_SERVER']]) + ->setBaseDn((string) getenv('LDAP_BASE_DN')) + ->setServers([(string) getenv('LDAP_SERVER')]) ->setSslCaCert( $_ENV['LDAP_CA_CERT'] === '' ? __DIR__ . '/../resources/cert/ca.crt' - : (string) $_ENV['LDAP_CA_CERT'] + : (string) getenv('LDAP_CA_CERT') ) - ->setBaseDn((string) $_ENV['LDAP_BASE_DN']); + ->setBaseDn((string) getenv('LDAP_BASE_DN')); } protected function getClient(?ClientOptions $options = null): LdapClient @@ -43,8 +43,8 @@ protected function getClient(?ClientOptions $options = null): LdapClient protected function bindClient(LdapClient $client): void { $client->bind( - $_ENV['LDAP_USERNAME'], - $_ENV['LDAP_PASSWORD'], + (string) getenv('LDAP_USERNAME'), + (string) getenv('LDAP_PASSWORD'), ); } diff --git a/tests/integration/Search/RangeRetrievalTest.php b/tests/integration/Search/RangeRetrievalTest.php index d2694cb2..f41dda02 100644 --- a/tests/integration/Search/RangeRetrievalTest.php +++ b/tests/integration/Search/RangeRetrievalTest.php @@ -17,6 +17,7 @@ use FreeDSx\Ldap\LdapClient; use FreeDSx\Ldap\Search\RangeRetrieval; use Tests\Integration\FreeDSx\Ldap\LdapTestCase; +use Throwable; class RangeRetrievalTest extends LdapTestCase { @@ -39,7 +40,7 @@ public function tearDown(): void { try { $this->client->unbind(); - } catch (\Exception|\Throwable $e) { + } catch (Throwable) { } } diff --git a/tests/resources/activedirectory/generate-ldif.php b/tests/resources/activedirectory/generate-ldif.php index 0fea5cda..774b7de4 100644 --- a/tests/resources/activedirectory/generate-ldif.php +++ b/tests/resources/activedirectory/generate-ldif.php @@ -2,7 +2,7 @@ # A simple script to modify the OpenLDAP LDIF data to work with AD so we are working with the same data set. -$data = file_get_contents(__DIR__ . '/../openldap/ldif/data.ldif'); +$data = (string) file_get_contents(__DIR__ . '/../openldap/ldif/data.ldif'); $ldif = explode("\n", $data); foreach ($ldif as $i => $line) { if (preg_match('/^userPassword/', $line)) { @@ -11,7 +11,7 @@ } file_put_contents(__DIR__ . '/ldif/data.ldif', implode("\n", $ldif)); -$data = file_get_contents(__DIR__ . '/../openldap/ldif/data-group.ldif'); +$data = (string) file_get_contents(__DIR__ . '/../openldap/ldif/data-group.ldif'); $ldif = explode("\n", $data); foreach ($ldif as $i => $line) { if (preg_match('/^objectClass/', $line)) { diff --git a/tests/unit/ContainerTest.php b/tests/unit/ContainerTest.php index 2ae1df95..daabfb2f 100644 --- a/tests/unit/ContainerTest.php +++ b/tests/unit/ContainerTest.php @@ -47,6 +47,9 @@ protected function setUp(): void ]); } + /** + * @return array + */ public static function buildableDependenciesDataProvider(): array { return [ diff --git a/tests/unit/Entry/EntryTest.php b/tests/unit/Entry/EntryTest.php index 03c4185b..3fd7e726 100644 --- a/tests/unit/Entry/EntryTest.php +++ b/tests/unit/Entry/EntryTest.php @@ -217,7 +217,7 @@ public function test_it_should_remove_an_attribute_using_an_attribute(): void self::assertNull($this->subject->get('cn', true)); } - public function if_should_check_if_it_has_an_attribute_using_a_string() + public function if_should_check_if_it_has_an_attribute_using_a_string(): void { self::assertTrue($this->subject->has('Cn')); self::assertFalse($this->subject->has('bleh')); diff --git a/tests/unit/LdapClientTest.php b/tests/unit/LdapClientTest.php index c251fff9..809dad67 100644 --- a/tests/unit/LdapClientTest.php +++ b/tests/unit/LdapClientTest.php @@ -155,46 +155,42 @@ public function test_it_should_bind(): void public function test_it_should_construct_a_pager_helper(): void { - self::assertInstanceOf( - Paging::class, - $this->subject->paging(Operations::search( - Filters::equal( - 'foo', - 'bar' - )) - ), + self::expectNotToPerformAssertions(); + + $this->subject->paging(Operations::search( + Filters::equal( + 'foo', + 'bar' + )) ); } public function test_it_should_construct_a_vlv_helper(): void { - self::assertInstanceOf( - Vlv::class, - $this->subject->vlv( - Operations::search(Filters::equal( - 'foo', - 'bar' - )), - 'cn', - 100 - ), + self::expectNotToPerformAssertions(); + + $this->subject->vlv( + Operations::search(Filters::equal( + 'foo', + 'bar' + )), + 'cn', + 100 ); } public function test_it_should_construct_a_dirsync_helper(): void { - self::assertInstanceOf( - DirSync::class, - $this->subject->dirSync() - ); + self::expectNotToPerformAssertions(); + + $this->subject->dirSync(); } public function test_it_should_construct_a_range_retrieval_helper(): void { - self::assertInstanceOf( - RangeRetrieval::class, - $this->subject->range(), - ); + self::expectNotToPerformAssertions(); + + $this->subject->range(); } public function test_it_should_start_tls(): void diff --git a/tests/unit/Operation/Request/AbandonRequestTest.php b/tests/unit/Operation/Request/AbandonRequestTest.php index fc1c08e9..d2a95eaf 100644 --- a/tests/unit/Operation/Request/AbandonRequestTest.php +++ b/tests/unit/Operation/Request/AbandonRequestTest.php @@ -28,11 +28,6 @@ protected function setUp(): void $this->subject = new AbandonRequest(1); } - public function testItIsInitializable(): void - { - $this->assertInstanceOf(AbandonRequest::class, $this->subject); - } - public function testItShouldGetTheMessageId(): void { $this->assertEquals(1, $this->subject->getMessageId()); diff --git a/tests/unit/Operation/Request/SearchRequestTest.php b/tests/unit/Operation/Request/SearchRequestTest.php index 0204aebc..3c45f229 100644 --- a/tests/unit/Operation/Request/SearchRequestTest.php +++ b/tests/unit/Operation/Request/SearchRequestTest.php @@ -214,6 +214,7 @@ public function test_it_should_not_allow_invalid_cancel_stragegies(): void { $this->expectException(UnexpectedValueException::class); + /** @phpstan-ignore-next-line */ $this->subject->useCancelStrategy('foo'); } diff --git a/tests/unit/Operation/Request/SimpleBindRequestTest.php b/tests/unit/Operation/Request/SimpleBindRequestTest.php index 12ed8681..3ec0bb69 100644 --- a/tests/unit/Operation/Request/SimpleBindRequestTest.php +++ b/tests/unit/Operation/Request/SimpleBindRequestTest.php @@ -15,6 +15,7 @@ use FreeDSx\Asn1\Asn1; use FreeDSx\Asn1\Type\AbstractType; +use FreeDSx\Asn1\Type\SequenceType; use FreeDSx\Ldap\Exception\BindException; use FreeDSx\Ldap\Exception\ProtocolException; use FreeDSx\Ldap\Operation\Request\SimpleBindRequest; @@ -67,7 +68,7 @@ public function test_it_should_allow_non_empty_username_and_password(): void ->setPassword('bar'); self::assertInstanceOf( - AbstractType::class, + SequenceType::class, $this->subject->toAsn1() ); } @@ -94,14 +95,7 @@ public function test_it_should_correctly_detect_a_zero_string_as_non_empty(): vo $this->subject->setPassword('0'); self::assertInstanceOf( - AbstractType::class, - $this->subject->toAsn1() - ); - - $this->subject->setUsername('0'); - - self::assertInstanceOf( - AbstractType::class, + SequenceType::class, $this->subject->toAsn1() ); } diff --git a/tests/unit/Operation/Response/AddResponseTest.php b/tests/unit/Operation/Response/AddResponseTest.php index 78d0c724..80c4aa95 100644 --- a/tests/unit/Operation/Response/AddResponseTest.php +++ b/tests/unit/Operation/Response/AddResponseTest.php @@ -29,7 +29,7 @@ protected function setUp(): void ); } - public function test_it_has_the_expected_tag_number() + public function test_it_has_the_expected_tag_number(): void { self::assertSame( 9, diff --git a/tests/unit/Protocol/ClientProtocolHandler/ClientSaslBindHandlerTest.php b/tests/unit/Protocol/ClientProtocolHandler/ClientSaslBindHandlerTest.php index f68a6018..69e2b4c8 100644 --- a/tests/unit/Protocol/ClientProtocolHandler/ClientSaslBindHandlerTest.php +++ b/tests/unit/Protocol/ClientProtocolHandler/ClientSaslBindHandlerTest.php @@ -249,6 +249,8 @@ public function test_it_should_set_the_set_the_security_layer_on_the_queue_if_on ->method('challenge') ->will(self::onConsecutiveCalls( (new SaslContext())->setResponse('foo'), + // The return types for SaslContext need to be updated. + // @phpstan-ignore-next-line (new SaslContext())->setResponse('foo') ->setHasSecurityLayer(true) ->setIsAuthenticated(true) diff --git a/tests/unit/Protocol/Queue/ClientQueueTest.php b/tests/unit/Protocol/Queue/ClientQueueTest.php index 406c6963..bb6f3c6b 100644 --- a/tests/unit/Protocol/Queue/ClientQueueTest.php +++ b/tests/unit/Protocol/Queue/ClientQueueTest.php @@ -104,10 +104,7 @@ public function test_it_should_get_a_response_message(): void ) ); - self::assertInstanceOf( - LdapMessageResponse::class, - $this->subject->getMessage(), - ); + $this->subject->getMessage(); } public function test_it_should_throw_an_unsolicited_notification_exception_when_one_is_received(): void @@ -201,9 +198,6 @@ public function test_it_should_set_a_message_wrapper_and_use_it_when_receiving_m $this->subject->setMessageWrapper($mockWrapper); - self::assertInstanceOf( - LdapMessageResponse::class, - $this->subject->getMessage(), - ); + $this->subject->getMessage(); } } diff --git a/tests/unit/Protocol/Queue/ServerQueueTest.php b/tests/unit/Protocol/Queue/ServerQueueTest.php index 6d15a223..73f8dade 100644 --- a/tests/unit/Protocol/Queue/ServerQueueTest.php +++ b/tests/unit/Protocol/Queue/ServerQueueTest.php @@ -76,6 +76,7 @@ public function test_it_should_send_a_message(): void public function test_it_should_get_a_request_message(): void { $this->mockEncoder + ->expects($this->once()) ->method('decode') ->willReturn( Asn1::sequence( @@ -85,10 +86,7 @@ public function test_it_should_get_a_request_message(): void ), ); - self::assertInstanceOf( - LdapMessageRequest::class, - $this->subject->getMessage(), - ); + $this->subject->getMessage(); } public function test_it_should_send_multiple_messages_with_write_and_respect_the_buffer_size(): void @@ -139,19 +137,18 @@ public function test_it_should_set_a_message_wrapper_and_use_it_when_receiving_m ); $this->mockEncoder + ->expects($this->once()) ->method('decode') ->willReturn($asn1); $mockWrapper = $this->createMock(MessageWrapperInterface::class); $mockWrapper + ->expects($this->once()) ->method('unwrap') ->willReturn(new Buffer('bar', 3)); $this->subject->setMessageWrapper($mockWrapper); - self::assertInstanceOf( - LdapMessageRequest::class, - $this->subject->getMessage(), - ); + $this->subject->getMessage(); } } diff --git a/tests/unit/Protocol/ServerAuthorizationTest.php b/tests/unit/Protocol/ServerAuthorizationTest.php index ba75a91f..9eb4abce 100644 --- a/tests/unit/Protocol/ServerAuthorizationTest.php +++ b/tests/unit/Protocol/ServerAuthorizationTest.php @@ -148,6 +148,9 @@ public function test_it_should_tell_if_a_request_is_not_an_authentication_type(R self::assertFalse($this->subject->isAuthenticationRequest($request)); } + /** + * @return array + */ public static function authExpectedRequestsDataProvider(): array { return [ diff --git a/tests/unit/Protocol/ServerProtocolHandler/ServerRootDseHandlerTest.php b/tests/unit/Protocol/ServerProtocolHandler/ServerRootDseHandlerTest.php index 3a1f21c8..761f5501 100644 --- a/tests/unit/Protocol/ServerProtocolHandler/ServerRootDseHandlerTest.php +++ b/tests/unit/Protocol/ServerProtocolHandler/ServerRootDseHandlerTest.php @@ -116,7 +116,7 @@ public function test_it_should_send_back_a_RootDSE_with_paging_support_if_the_pa $entry = $search->getEntry(); return $entry->get('supportedControl') - ->has(Control::OID_PAGING); + ?->has(Control::OID_PAGING) ?? false; }), new LdapMessageResponse(1, new SearchResultDone(0)), ); @@ -226,10 +226,10 @@ public function test_it_should_only_return_specific_attributes_from_the_RootDSE_ ->setAttributes('namingcontexts') ); - # The reset below is needed, unfortunately, to properly spec due to how the objects change... + # The reset below is needed, unfortunately, to properly test due to how the objects change... $entry = Entry::create('', ['namingContexts' => 'dc=Foo,dc=Bar', ]); $entry->changes()->reset(); - $entry->get('namingContexts')->equals(new Attribute('foo')); + $entry->get('namingContexts')?->equals(new Attribute('foo')); $this->mockQueue ->expects($this->once()) diff --git a/tests/unit/Search/DirSyncTest.php b/tests/unit/Search/DirSyncTest.php index 743d0982..86269eff 100644 --- a/tests/unit/Search/DirSyncTest.php +++ b/tests/unit/Search/DirSyncTest.php @@ -23,6 +23,7 @@ use FreeDSx\Ldap\Protocol\LdapMessageResponse; use FreeDSx\Ldap\Search\DirSync; use FreeDSx\Ldap\Search\Filters; +use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\Rule\InvocationOrder; use PHPUnit\Framework\TestCase; @@ -265,18 +266,18 @@ public function test_it_should_return_false_for_changes_if_the_dir_sync_control_ } /** - * @param mixed ...$arguments + * @param Constraint ...$arguments */ private function addSendExpectation(...$arguments): void { $this->client ->expects($this->once()) ->method('send') - ->with(...$arguments) + ->with(...array_values($arguments)) ->willReturn($this->initialResponse); } /** - * @param mixed ...$arguments + * @param Constraint ...$arguments */ private function addSendAndOrderExpectation( InvocationOrder $order, @@ -285,7 +286,7 @@ private function addSendAndOrderExpectation( $this->client ->expects($order) ->method('send') - ->with(...$arguments) + ->with(...array_values($arguments)) ->willReturn($this->initialResponse); } } diff --git a/tests/unit/Search/RangeRetrievalTest.php b/tests/unit/Search/RangeRetrievalTest.php index 0878e9df..e74c7d63 100644 --- a/tests/unit/Search/RangeRetrievalTest.php +++ b/tests/unit/Search/RangeRetrievalTest.php @@ -116,8 +116,9 @@ public function test_it_should_get_more_values_for_a_ranged_attribute(): void ->with( 'dc=foo', $this->callback(function ($attr) { - return $attr[0]->getOptions()->first()->getLowRange() == '1501' - && $attr[0]->getOptions()->first()->getHighRange() == '*'; + /** @var Attribute[] $attr */ + return $attr[0]->getOptions()->first()?->getLowRange() == '1501' + && $attr[0]->getOptions()->first()?->getHighRange() == '*'; }) ) ->willReturn($entry); @@ -142,7 +143,8 @@ public function test_it_should_use_a_specific_ranged_amount_of_values_to_retriev ->with( 'dc=foo', $this->callback(function ($attr) { - return $attr[0]->getOptions()->first()->getLowRange() === '1501' + /** @var Attribute[] $attr */ + return $attr[0]->getOptions()->first()?->getLowRange() === '1501' && $attr[0]->getOptions()->first()->getHighRange() === '1600'; }) ) diff --git a/tests/unit/Server/RequestHistoryTest.php b/tests/unit/Server/RequestHistoryTest.php index c11be99b..8d3646f0 100644 --- a/tests/unit/Server/RequestHistoryTest.php +++ b/tests/unit/Server/RequestHistoryTest.php @@ -55,9 +55,8 @@ public function test_it_should_throw_when_adding_an_invalid_id(): void public function test_it_should_get_the_paging_requests(): void { - self::assertInstanceOf( - PagingRequests::class, - $this->subject->pagingRequest() + self::assertFalse( + $this->subject->pagingRequest()->has('foo') ); } } diff --git a/tests/unit/Server/ServerProtocolFactoryTest.php b/tests/unit/Server/ServerProtocolFactoryTest.php index c8fddda5..db956b5c 100644 --- a/tests/unit/Server/ServerProtocolFactoryTest.php +++ b/tests/unit/Server/ServerProtocolFactoryTest.php @@ -52,9 +52,6 @@ public function test_it_should_make_a_ServerProtocolInstance(): void ->method('makeRequestHandler') ->willReturn(new GenericRequestHandler()); - self::assertInstanceOf( - ServerProtocolHandler::class, - $this->subject->make($mockSocket) - ); + $this->subject->make($mockSocket); } } diff --git a/tests/unit/Server/SocketServerFactoryTest.php b/tests/unit/Server/SocketServerFactoryTest.php index eb2f9f36..6b832643 100644 --- a/tests/unit/Server/SocketServerFactoryTest.php +++ b/tests/unit/Server/SocketServerFactoryTest.php @@ -37,7 +37,7 @@ final class SocketServerFactoryTest extends TestCase protected function setUp(): void { $this->tmpUnixSocketResource = $this->makeTempFile();; - $this->tmpUnixSocketFilePath = stream_get_meta_data($this->tmpUnixSocketResource)['uri']; + $this->tmpUnixSocketFilePath = stream_get_meta_data($this->tmpUnixSocketResource)['uri'] ?? throw new RuntimeException('Unable to get temp file path for unix socket.'); $this->mockLogger = $this->createMock(LoggerInterface::class); $this->subject = new SocketServerFactory( @@ -54,10 +54,9 @@ protected function tearDown(): void public function test_it_should_make_and_bind_the_socket_server(): void { - self::assertInstanceOf( - SocketServer::class, - $this->subject->makeAndBind(), - ); + self::expectNotToPerformAssertions(); + + $this->subject->makeAndBind(); } public function test_it_should_make_a_unix_based_socket_server(): void @@ -65,6 +64,7 @@ public function test_it_should_make_a_unix_based_socket_server(): void if (str_starts_with(strtoupper(PHP_OS), 'WIN')) { $this->markTestSkipped('Cannot construct unix based socket on Windows.'); } + self::expectNotToPerformAssertions(); $this->subject = new SocketServerFactory( (new ServerOptions()) @@ -73,10 +73,7 @@ public function test_it_should_make_a_unix_based_socket_server(): void $this->mockLogger, ); - self::assertInstanceOf( - SocketServer::class, - $this->subject->makeAndBind(), - ); + $this->subject->makeAndBind(); } /** From 28e4235f8245b2890903874baacc106442bb43b0 Mon Sep 17 00:00:00 2001 From: Chad Sikorra Date: Sun, 30 Nov 2025 12:36:04 -0500 Subject: [PATCH 2/2] Bump phpstan to level 10 for tests. --- phpstan.tests.neon | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpstan.tests.neon b/phpstan.tests.neon index 3a7550e8..09871428 100644 --- a/phpstan.tests.neon +++ b/phpstan.tests.neon @@ -1,4 +1,5 @@ parameters: - level: 3 + treatPhpDocTypesAsCertain: false + level: 10 paths: - %currentWorkingDirectory%/tests