Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.2 - Fix deprecated callable patterns in unit test #285

Merged

Conversation

hungtrinh
Copy link

@hungtrinh hungtrinh commented Nov 18, 2022

Fix "Known issue" section of PR #275

Expected Result

Those test case bellow pass without "deprecated message" on php 8.2 (same as php 7.4, php 8.0, php 8.1)

Actual Result

$ docker run -v $(pwd):$(pwd) -w $(pwd) -t --rm php:8.2-rc-cli-alpine -d memory_limit=-1 ./bin/phpunit -v --bootstrap tests/TestHelper.php tests/Zend/EventManager/EventManagerTest.php    

PHPUnit 9.5.25 #StandWithUkraine

.
Deprecated: Callables of the form ["Zend_EventManager_EventManagerTest", "Zend_EventManager_EventManagerTest::testAttachShouldReturnCallbackHandler"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
.
Deprecated: Callables of the form ["Zend_EventManager_EventManagerTest", "Zend_EventManager_EventManagerTest::testAttachShouldAddListenerToEvent"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
.
Deprecated: Callables of the form ["Zend_EventManager_EventManagerTest", "Zend_EventManager_EventManagerTest::testAttachShouldAddEventIfItDoesNotExist"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
...
Deprecated: Callables of the form ["Zend_EventManager_EventManagerTest", "Zend_EventManager_EventManagerTest::testDetachShouldRemoveListenerFromEvent"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
.
Deprecated: Callables of the form ["Zend_EventManager_EventManagerTest", "Zend_EventManager_EventManagerTest::testDetachShouldReturnFalseIfEventDoesNotExist"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
.
Deprecated: Callables of the form ["Zend_EventManager_EventManagerTest", "Zend_EventManager_EventManagerTest::testDetachShouldReturnFalseIfListenerDoesNotExist"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
...........................S......                        42 / 42 (100%)

Time: 00:00.097, Memory: 6.00 MB

OK, but incomplete, skipped, or risky tests!
Tests: 42, Assertions: 119, Skipped: 1.
docker run -v $(pwd):$(pwd) -w $(pwd) -t --rm php:8.2-rc-cli-alpine -d memory_limit=-1 ./bin/phpunit -v --bootstrap tests/TestHelper.php tests/Zend/EventManager/FilterChainTest.php

PHPUnit 9.5.25 #StandWithUkraine

.
Deprecated: Callables of the form ["Zend_EventManager_FilterChainTest", "Zend_EventManager_FilterChainTest::testSubscribeShouldReturnCallbackHandler"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
.
Deprecated: Callables of the form ["Zend_EventManager_FilterChainTest", "Zend_EventManager_FilterChainTest::testSubscribeShouldAddCallbackHandlerToFilters"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
.
Deprecated: Callables of the form ["Zend_EventManager_FilterChainTest", "Zend_EventManager_FilterChainTest::testDetachShouldRemoveCallbackHandlerFromFilters"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
.
Deprecated: Callables of the form ["Zend_EventManager_FilterChainTest", "Zend_EventManager_FilterChainTest::testDetachShouldReturnFalseIfCallbackHandlerDoesNotExist"] are deprecated in /Users/trinhhung/Projects/zf1-future/library/Zend/Stdlib/CallbackHandler.php on line 97
.....                                                           9 / 9 (100%)

Time: 00:00.110, Memory: 6.00 MB

OK (9 tests, 13 assertions)

List test case raise deprecated message

public function testAttachShouldReturnCallbackHandler()
{
$listener = $this->events->attach('test', [$this, __METHOD__]);
$this->assertTrue($listener instanceof Zend_Stdlib_CallbackHandler);
}
public function testAttachShouldAddListenerToEvent()
{
$listener = $this->events->attach('test', [$this, __METHOD__]);
$listeners = $this->events->getListeners('test');
$this->assertEquals(1, count($listeners));
$this->assertContains($listener, $listeners);
}
public function testAttachShouldAddEventIfItDoesNotExist()
{
$events = $this->events->getEvents();
$this->assertTrue(empty($events), var_export($events, 1));
$listener = $this->events->attach('test', [$this, __METHOD__]);
$events = $this->events->getEvents();
$this->assertFalse(empty($events));
$this->assertContains('test', $events);
}

public function testDetachShouldRemoveListenerFromEvent()
{
$listener = $this->events->attach('test', [$this, __METHOD__]);
$listeners = $this->events->getListeners('test');
$this->assertContains($listener, $listeners);
$this->events->detach($listener);
$listeners = $this->events->getListeners('test');
$this->assertNotContains($listener, $listeners);
}
public function testDetachShouldReturnFalseIfEventDoesNotExist()
{
$listener = $this->events->attach('test', [$this, __METHOD__]);
$this->events->clearListeners('test');
$this->assertFalse($this->events->detach($listener));
}
public function testDetachShouldReturnFalseIfListenerDoesNotExist()
{
$listener1 = $this->events->attach('test', [$this, __METHOD__]);
$this->events->clearListeners('test');
$listener2 = $this->events->attach('test', [$this, 'handleTestEvent']);
$this->assertFalse($this->events->detach($listener1));
}

public function testSubscribeShouldReturnCallbackHandler()
{
$handle = $this->filterchain->attach([ $this, __METHOD__ ]);
$this->assertTrue($handle instanceof Zend_Stdlib_CallbackHandler);
}
public function testSubscribeShouldAddCallbackHandlerToFilters()
{
$handler = $this->filterchain->attach([$this, __METHOD__]);
$handlers = $this->filterchain->getFilters();
$this->assertEquals(1, count($handlers));
$this->assertTrue($handlers->contains($handler));
}
public function testDetachShouldRemoveCallbackHandlerFromFilters()
{
$handle = $this->filterchain->attach([ $this, __METHOD__ ]);
$handles = $this->filterchain->getFilters();
$this->assertTrue($handles->contains($handle));
$this->filterchain->detach($handle);
$handles = $this->filterchain->getFilters();
$this->assertFalse($handles->contains($handle));
}
public function testDetachShouldReturnFalseIfCallbackHandlerDoesNotExist()
{
$handle1 = $this->filterchain->attach([ $this, __METHOD__ ]);
$this->filterchain->clearFilters();
$handle2 = $this->filterchain->attach([ $this, 'handleTestTopic' ]);
$this->assertFalse($this->filterchain->detach($handle1));
}

PHP call stack raise deprecated message

Sample 1 test case only:

CALL STACK

Solution

Deprecated pattern: is_callable([new MyClass(), "MyOtherClass::myMethod"])
Migrate to pattern: is_callable([new MyClass(), "myMethod"])

Deprecated pattern: is_callable([new MyClass(), "MyOtherClass::myMethod"])

Migrate to pattern: is_callable([new MyClass(), "myMethod"])
@glensc
Copy link
Collaborator

glensc commented Nov 18, 2022

🚧 Never link to branches, share a permalink 🚧

NOTE: edit your post and fix it with a permalink!

@hungtrinh
Copy link
Author

wow, bro @glensc thanks about tip hit y ^^ it saves me time

@hungtrinh
Copy link
Author

@Jimbolino Jimbolino merged commit 3629633 into Shardj:master Nov 19, 2022
@hungtrinh hungtrinh deleted the fix-is_callable-deprecated-on-php82 branch March 7, 2023 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants