plugin development – PHPUnit Ajax Serialization of ‘Closure’ is not allowed

Question

Trying to set up a simple AJAX unit test and I get this error.

Serialization of ‘Closure’ is not allowed

Things I installed

  • wp scaffold plugin testplugin (also can use wp scaffold plugin-tests testplugin for existing plugins)
  • composer require phpunit/phpunit ^9 --dev
  • composer require yoast/phpunit-polyfills --dev

This is the actual test class I was trying…

/**
 * Test cases for AJAX functions
 *
 * Bagla-Group Hindustan Adhesive ajax
 * @runTestsInSeparateProcesses
 */
class AjaxTest extends WP_Ajax_UnitTestCase {

    public function setUp(): void
    {
        parent::setUp();
    }

    public function testIsTrue(): void
    {
        $this->assertTrue( true );
    }
}

Full output

./vendor/bin/phpunit --group=ajax --verbose --debug
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 9.5.24 #StandWithUkraine

Runtime:       PHP 8.1.9
Configuration: /var/www/test/wp-content/plugins/testplugin/phpunit.xml.dist

Serialization of 'Closure' is not allowed

EDIT: Realized that according to the WP/PHPUnit compatability matrix, PHP 8.1 is not supported. So I tried again with PHP 8.0. However, I get the same error.

./vendor/bin/phpunit --group=ajax --debug --verbose

Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 9.5.24 #StandWithUkraine

Runtime:       PHP 8.0.22
Configuration: /var/www/test/wp-content/plugins/testplugin/phpunit.xml.dist

Serialization of 'Closure' is not allowed

EDIT 2: Also noticed Not running ajax tests. To execute these, use --group ajax. because I was using --group=ajax and not --group ajax. So I tried this, but still get the same error.

0
Brennan 3 weeks 2022-09-02T09:19:47-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse