Skip to content

Instantly share code, notes, and snippets.

@Chrysweel
Last active August 29, 2015 14:02
Show Gist options
  • Save Chrysweel/bbf4d6454c1822eac57b to your computer and use it in GitHub Desktop.
Save Chrysweel/bbf4d6454c1822eac57b to your computer and use it in GitHub Desktop.
Test
<?php
public function testSecurityRolesCanCreateChannelAction()
{
// Create a new client to browse the application
$client = static::createClient();
$mock_event_dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
->disableOriginalConstructor()
->getMock();
static::$kernel->getContainer()->set('event_dispatcher', $mock_event_dispatcher);
// $client->getContainer()->set('event_dispatcher', $mock_event_dispatcher);
$url = sprintf('/api/channels.json?access_token=%s',$this->getOAuthAccessTokenUserEnabled());
$parameters = array(
'name' => 'name_moderator',
'irc_channel' => '#name_moderator',
'description' => 'Description of test moderator',
'channel_type' => 'adult'
);
// Create a new entry in the database
$client->request(
'POST',
$url,
$parameters,
array(),
array('HTTP_Accept' => 'application/json')
);
$response = $client->getResponse();
$this->assertEquals(201, $response->getStatusCode(), "Unexpected HTTP status code for GET /api/channels/create...");
}
<?php
static protected function createClient(array $options = array(), array $server = array())
{
if (null !== static::$kernel) {
static::$kernel->shutdown();
}
static::$kernel = static::createKernel($options);
static::$kernel->boot();
$client = static::$kernel->getContainer()->get('test.client');
$client->setServerParameters($server);
return $client;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment