Skip to content

Instantly share code, notes, and snippets.

@jubianchi
Forked from anonymous/ControllerTest.php
Last active December 9, 2015 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jubianchi/4336789 to your computer and use it in GitHub Desktop.
Save jubianchi/4336789 to your computer and use it in GitHub Desktop.
This is an example usage of the AtoumBundle RFC with an improved syntax matching atoum's standards. https://github.com/atoum/AtoumBundle/pull/8 https://github.com/atoum/AtoumBundle/issues/15
<?php
namespace Acme\DemoBundle\Tests\Controller;
require_once __DIR__ . '/../../../../vendor/autoload.php';
require_once __DIR__ . '/../../../../vendor/atoum/atoum/scripts/runner.php';
use atoum\AtoumBundle\Test\Controller;
class DemoController extends Controller\ControllerTest
{
public function testIndexAction()
{
$this
->request(array('debug' => true))
->GET('/demo')
->hasStatus(301)
->GET('/demo/')
->hasStatus(200)
->hasCharset('UTF-8')
->hasVersion('1.1')
;
}
public function testContactActionWithActualSyntax()
{
$this
->request(array('debug' => true))
->GET('/demo/contact' . uniqid())
->hasStatus(404)
->hasCharset('UTF-8')
->hasVersion('1.1')
->POST('/demo/contact')
->hasStatus(200)
->hasHeader('Content-Type', 'text/html; charset=UTF-8')
->crawler
->hasElement('#contact_form')->exactly(1)
->hasChild('input')->exactly(3)->end()
->hasChild('input')
->withAttribute('type', 'email')
->withAttribute('name', 'contact[email]')
->end()
->hasChild('input[type=submit]')
->withAttribute('value', 'Send')
->end()
->hasChild('textarea')->end()
->end()
->hasElement('li')
->withContent('The CSRF token is invalid. Please try to resubmit the form.')
->exactly(1)
->end()
;
}
public function testContactActionWithProposedSyntax()
{
$this
->request(array('debug' => true))
->GET('/demo/contact' . uniqid())
->hasStatus(404)
->hasCharset('UTF-8')
->hasVersion('1.1')
->POST('/demo/contact')
->hasStatus(200)
->hasHeader('Content-Type', 'text/html; charset=UTF-8')
->crawler
->hasElement('#contact_form')
->hasChild('input')->exactly(3)
->hasChild('textarea')->isEmpty() // Automatically fallback to ->atLeast(1)
->hasChild('input[type=submit]')->exactly(1)
->hasChild('input[type=email][name="email"contact[email]"]')->exactly(1)
->hasChild('input[type=submit]')->exactly(1)
->crawler // As we request the Crawler, ->atLeast(1) is implicitly called
->hasElement('h1')->withContent('Contact')
->crawler
->hasElement('small')->withContent('Send us a message')
->parent() // Close the crawler, setting the scope back to #contact_form children
->parent() // Close the crawler, setting the scope back to #contact_form element
->exactly(1) // Refers to #contact_form
->hasElement('li')->exactly(1)
->withContent('The CSRF token is invalid. Please try to resubmit the form.')
->exactly(1)
;
}
}
@jubianchi
Copy link
Author

@jubianchi
Copy link
Author

This PR was merged (atoum/AtoumBundle#8).
This gist is now related to the discussion under issue #15 (atoum/AtoumBundle#15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment