diff --git a/Tests/Integration/FunctionsTest.php b/Tests/Integration/FunctionsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..44ce1602e10188fc44136066475031b8a1467c31 --- /dev/null +++ b/Tests/Integration/FunctionsTest.php @@ -0,0 +1,31 @@ +<?php + + +namespace calderawp\CalderaFormsQuery\Tests\Integration; + + +use function calderawp\CalderaFormsQueries\CalderaFormsQueries; +use calderawp\CalderaFormsQuery\Features\FeatureContainer; + +class FunctionsTest extends IntegrationTestCase +{ + + /** + * Ensure that accessor function returns the right class type + * @covers CalderaFormsQueries() + */ + public function testGetMainInstance() + { + $this->assertSame( FeatureContainer::class, get_class(CalderaFormsQueries()) ); + } + /** + * Ensure that accessor function returns the same class instance + * @covers CalderaFormsQueries() + */ + public function testIsSameInstance() + { + $this->assertSame( CalderaFormsQueries(), CalderaFormsQueries() ); + CalderaFormsQueries()->set('sivan', 'roy' ); + $this->assertEquals( 'roy', CalderaFormsQueries()->get('sivan') ); + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index ef179fa73ede6110e074b5141867b650a75e5d30..7adef13f4eeaa0e83c33fb58f0ea0753ea0e8e35 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "autoload": { "psr-4": { "calderawp\\CalderaFormsQuery\\": "src" - } + }, + "files": ["src/CalderaFormsQueries.php"] }, "scripts" : { "tests" : "composer unit-tests && composer wp-tests", diff --git a/src/CalderaFormsQueries.php b/src/CalderaFormsQueries.php new file mode 100644 index 0000000000000000000000000000000000000000..a901472b2b922b4dbf50bab091979b95b5541561 --- /dev/null +++ b/src/CalderaFormsQueries.php @@ -0,0 +1,27 @@ +<?php + +namespace calderawp\CalderaFormsQueries; + +use calderawp\CalderaContainers\Service\Container; +use calderawp\CalderaFormsQuery\Features\FeatureContainer; + +/** + * The CalderaFormsQueries + * + * Acts as static accessor for feature container + * + * @return FeatureContainer + */ +function CalderaFormsQueries() +{ + static $CalderaFormsQueries; + if( ! $CalderaFormsQueries ){ + global $wpdb; + $CalderaFormsQueries = new FeatureContainer( + new Container(), + $wpdb + ); + } + + return $CalderaFormsQueries; +} \ No newline at end of file