PHP code example of pretzlaw / wp-integration-test
1. Go to this page and download the library: Download pretzlaw/wp-integration-test library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pretzlaw / wp-integration-test example snippets
class FooTest extends \PHPUnit\Framework\TestCase {
use \Pretzlaw\WPInt\Traits\WordPressTests;
function testBar() {
// Assertions (simple or with special constraints)
static::assertActionHasCallback( 'init', 'my_own_init' );
static::assertShortcodeHasCallback(
[ new IsInstanceOf( MyOwn::class ), 'some_method' ],
'my_shortcode'
);
// Mock posts or meta-data
$this->mockGetPost( 1337 )->andReturn( /* your wp post mock */ );
$this->mockPostMeta( 'some_key' )->andReturn( 'Some value!' ); // For all posts
$this->mockMetaData( 'my-own-cpt', 'another_key', 1337 )->andReturn( 'ec' ); // Just for ID 1337
// Mock actions, filter, cache, ...
$this->mockFilter( 'user_has_cap' )
->andReturn( true );
$this->mockCache()
->shouldReceive('get')
->with('my_own_cache')
->andReturn('yeah');
// Or use one of several shortcuts and helper
$this->disableWpDie();
}
}
xml
<phpunit bootstrap="vendor/Pretzlaw/WPInt/bootstrap.php">
<testsuites>
<testsuite name="default">
<!-- CHANGE THIS TO WHERE YOUR PHPUNIT TEST CLASSES ARE -->
<directory>lib/tests</directory>
</testsuite>
</testsuites>
</phpunit>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.