Skip to content
Snippets Groups Projects
Commit a3f8716f authored by Dyszczo's avatar Dyszczo
Browse files

Merge branch 'feature/storage-test' into 'master'

Feature/storage test

See merge request !25
parents 2109111b c1caec75
No related branches found
Tags 1.6.2
1 merge request!25Feature/storage test
Pipeline #8629 passed with stages
in 3 minutes and 18 seconds
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
> >
<testsuites> <testsuites>
<testsuite> <testsuite>
<directory prefix="test-" suffix=".php">./tests/integration</directory> <directory prefix="Test_" suffix=".php">./tests/integration</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
...@@ -25,4 +25,4 @@ ...@@ -25,4 +25,4 @@
<env name="WC_DEVELOP_DIR" value="/tmp/woocommerce"/> <env name="WC_DEVELOP_DIR" value="/tmp/woocommerce"/>
</php> </php>
</phpunit> </phpunit>
\ No newline at end of file
...@@ -17,7 +17,7 @@ class WordpressFilterStorage implements PluginStorage { ...@@ -17,7 +17,7 @@ class WordpressFilterStorage implements PluginStorage {
* @param AbstractPlugin $object * @param AbstractPlugin $object
*/ */
public function add_to_storage( $class, $object ) { public function add_to_storage( $class, $object ) {
add_filter( self::STORAGE_FILTER_NAME, function ( $plugins ) use ( $class, $object ) { add_filter( self::STORAGE_FILTER_NAME, static function ( $plugins ) use ( $class, $object ) {
if ( isset( $plugins[ $class ] ) ) { if ( isset( $plugins[ $class ] ) ) {
throw new Exception\ClassAlreadyExists( "Class {$class} already exists" ); throw new Exception\ClassAlreadyExists( "Class {$class} already exists" );
} }
......
<?php
use WPDesk\Plugin\Flow\Initialization\Simple\SimpleStrategy;
use WPDesk\PluginBuilder\Storage\Exception\ClassNotExists;
use WPDesk\PluginBuilder\Storage\WordpressFilterStorage;
class Test_WordpressFilterStorage extends WP_UnitTestCase {
public function test_can_read_and_write() {
$storage = new WordpressFilterStorage();
$storage->add_to_storage( Test_WordpressFilterStorage::class, $this );
$this->assertInstanceOf( Test_WordpressFilterStorage::class,
$storage->get_from_storage( Test_WordpressFilterStorage::class ),
'Returned instance should be the same as saved' );
}
public function test_empty_storage_is_empty() {
$storage = new WordpressFilterStorage();
$this->expectException( ClassNotExists::class );
$storage->get_from_storage( Test_WordpressFilterStorage::class );
}
}
...@@ -18,7 +18,6 @@ if ( getenv( 'PLUGIN_PATH' ) !== false ) { ...@@ -18,7 +18,6 @@ if ( getenv( 'PLUGIN_PATH' ) !== false ) {
require_once( getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit/includes/functions.php' ); require_once( getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit/includes/functions.php' );
tests_add_filter( 'muplugins_loaded', function () { tests_add_filter( 'muplugins_loaded', function () {
$plugins_to_active[] = 'hello.php';
update_option( 'active_plugins', $plugins_to_active ); update_option( 'active_plugins', $plugins_to_active );
}, 100 ); }, 100 );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment