Use DI container whever possible

This commit is contained in:
Amine Ben hammou
2019-01-29 18:00:26 +01:00
parent 8b602bd947
commit f83b7453fc
2 changed files with 7 additions and 10 deletions

View File

@ -32,10 +32,7 @@ class API {
const CURRENT_VERSION = 'v1'; const CURRENT_VERSION = 'v1';
function __construct(ContainerInterface $container, AccessControl $access_control, WPFunctions $wp = null) { function __construct(ContainerInterface $container, AccessControl $access_control, WPFunctions $wp) {
if($wp === null) {
$wp = new WPFunctions;
}
$this->wp = $wp; $this->wp = $wp;
$this->container = $container; $this->container = $container;
$this->access_control = $access_control; $this->access_control = $access_control;

View File

@ -41,7 +41,7 @@ class APITest extends \MailPoetTest {
$this->container->autowire(APITestNamespacedEndpointStubV1::class)->setPublic(true); $this->container->autowire(APITestNamespacedEndpointStubV1::class)->setPublic(true);
$this->container->autowire(APITestNamespacedEndpointStubV2::class)->setPublic(true); $this->container->autowire(APITestNamespacedEndpointStubV2::class)->setPublic(true);
$this->container->compile(); $this->container->compile();
$this->api = new \MailPoet\API\JSON\API($this->container, $this->container->get(AccessControl::class)); $this->api = new \MailPoet\API\JSON\API($this->container, $this->container->get(AccessControl::class), new WPFunctions);
} }
function testItCallsAPISetupAction() { function testItCallsAPISetupAction() {
@ -196,7 +196,7 @@ class APITest extends \MailPoetTest {
new AccessControl(), new AccessControl(),
array('validatePermission' => false) array('validatePermission' => false)
); );
$api = new JSONAPI($this->container, $access_control); $api = new JSONAPI($this->container, $access_control, new WPFunctions);
$api->addEndpointNamespace($namespace['name'], $namespace['version']); $api->addEndpointNamespace($namespace['name'], $namespace['version']);
$api->setRequestData($data); $api->setRequestData($data);
$response = $api->processRoute(); $response = $api->processRoute();
@ -217,7 +217,7 @@ class APITest extends \MailPoetTest {
}) })
) )
); );
$api = new JSONAPI($this->container, $access_control); $api = new JSONAPI($this->container, $access_control, new WPFunctions);
expect($api->validatePermissions(null, $permissions))->false(); expect($api->validatePermissions(null, $permissions))->false();
$access_control = Stub::make( $access_control = Stub::make(
@ -229,7 +229,7 @@ class APITest extends \MailPoetTest {
}) })
) )
); );
$api = new JSONAPI($this->container, $access_control); $api = new JSONAPI($this->container, $access_control, new WPFunctions);
expect($api->validatePermissions(null, $permissions))->true(); expect($api->validatePermissions(null, $permissions))->true();
} }
@ -250,7 +250,7 @@ class APITest extends \MailPoetTest {
}) })
) )
); );
$api = new JSONAPI($this->container, $access_control); $api = new JSONAPI($this->container, $access_control, new WPFunctions);
expect($api->validatePermissions('test', $permissions))->false(); expect($api->validatePermissions('test', $permissions))->false();
$access_control = Stub::make( $access_control = Stub::make(
@ -262,7 +262,7 @@ class APITest extends \MailPoetTest {
}) })
) )
); );
$api = new JSONAPI($this->container, $access_control); $api = new JSONAPI($this->container, $access_control, new WPFunctions);
expect($api->validatePermissions('test', $permissions))->true(); expect($api->validatePermissions('test', $permissions))->true();
} }