Presents :
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
At WP Media since 2 years
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
Testing is limited.
J.B., WP Media CEO
In one quote....
2022
Testing should be an OKR.
J.B., WP Media CEO
2024
or maybe two
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
Guide you toward effective testing
Summary:
06/10/2023
COQUARD Cyrille
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
do_action(
'grant_admin',
wp_current_user()
);
do_action('logout');
$this->assertSame(
false,
apply_filters(
'user_can_edit',
false
)
);
}
}
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
COQUARD Cyrille
06/10/2023
Need to re-implement a way to interact with the element for each test
Use action and filter to cut your logic into small units
COQUARD Cyrille
06/10/2023
Use action and filter to cut your logic into small units
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
do_action(
'grant_admin',
wp_current_user()
);
do_action('logout');
$this->assertSame(
false,
apply_filters(
'user_can_edit',
false
)
);
}
}
COQUARD Cyrille
06/10/2023
Need control flow to direct the test into a certain state
Mock the filter with a callback function
COQUARD Cyrille
06/10/2023
Mock the filter with a callback function
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
...
}
/**
* @hook my_filter 10
*/
public function my_callback() {
return true;
}
}
COQUARD Cyrille
06/10/2023
The code call an external API and there is no control about it
Use wp_remote_request and mock the filter with a callback function
COQUARD Cyrille
06/10/2023
Use wp_remote_request and mock the filter with a callback function
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
...
}
/**
* @hook my_filter 10
*/
public function my_callback() {
return true;
}
}
COQUARD Cyrille
06/10/2023
The callback to test is linked to an hook with lot of callbacks making lot of noise
Isolate the callback by removing all other callbacks
COQUARD Cyrille
06/10/2023
Isolate the callback by removing all other callbacks
<?php
class Test_Logout extends TestCase {
public function testLogoutShouldNotEdit()
{
do_action(
'grant_admin',
wp_current_user()
);
do_action('logout');
$this->assertSame(
false,
apply_filters(
'user_can_edit',
false
)
);
}
}
https://github.com/wp-launchpad/launchpad
COQUARD Cyrille
06/10/2023
06/10/2023
COQUARD Cyrille