public function testDelete() { $manager = new PolicyManager(); $manager->setClient($this->client); $manager->setLogger($this->logger); $this->logger->expects($this->once())->method('info')->with('Delete policy <info>exTest</info> from vhost <info>test</info>'); $this->client->expects($this->once())->method('query')->with(ClientInterface::METHOD_DELETE, '/api/policies/test/exTest')->willReturn(true); $this->assertEquals(true, $manager->delete('test', 'exTest')); }
public function deletePolicies($vhost, $policies) { if ('*' === $policies) { //so you want to destroy all policies, as you whish, let me time to list'em all $policies = $this->policyManager->getAll(urlencode($vhost)); } elseif (!$vhost) { throw new \InvalidArgumentException('If you want to delete certain policie(s) you have to provide vhost'); } else { //few policies to delete, let stack them in array $policies = explode(',', $policies); array_walk($policies, function (&$item, $key, $vhost) { $item = ['vhost' => $vhost, 'name' => trim($item)]; }, $vhost); } if (0 == count($policies)) { $this->logger->error('No policy found.'); return; } foreach ($policies as $policy) { $this->policyManager->delete(urlencode($policy['vhost']), $policy['name']); } }