2017 © Pedro Peláez
 

library haphazard

Library for quick and dirty page functional testing

image

ink/haphazard

Library for quick and dirty page functional testing

  • Thursday, June 26, 2014
  • by MaxVandervelde
  • Repository
  • 2 Watchers
  • 1 Stars
  • 541 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Haphazard

Haphazard is a library extension to Symfony's WebTestCase that provides a quick and dirty method to functional test basic pages., (*1)

Installation

You can install Haphazard through composer:, (*2)

composer.phar require ink/haphazard

Usage

Simple page load test

When all you want to test is that the page at least loads properly, you can use the HaphazardTestCase::assertGet() or HaphazardTestCase::assertPost() methods. This will create a web client and assert that a response code of 200 is returned for the page., (*3)

use Ink\Haphazard\TestCase\HaphazardTestCase;

class ProductControllerTest extends HaphazardTestCase
{
    /**
     * Test Index Action
     */
    public function testIndexAction()
    {
        $this->assertGet('index');
    }

    /**
     * Test Post Action
     */
     public function testCreatePostAction()
     {
         $this->assertPost('create');
     }
}

Page with parameters

If the page you're testing requires parameters, you can pass those in as well., (*4)

/**
 * Test View Action
 */
public function testViewAction()
{
    $this->assertGet('product-view', ['productId' => 1]);
}

/**
 * Test Edit Action
 */
 public function testEditAction()
 {
     $this->assertPost('product-edit', ['productId' => 1]);
 }

Page with a Post body

If you need to send additional parameters along with your POST request, you can send them along., (*5)

/**
 * Test Edit Action
 */
 public function testEditAction()
 {
     $this->assertPost('product-edit', ['productId' => 1], ['product-name' => 'Acme Product']);
 }

Different Status codes

Occasionally you will want to test that pages return a different status code, for example a 403 / Forbidden status code when an anonymous user should not be able to access a given page, or a 302 when the page redirects., (*6)

/**
 * Test Edit Action
 */
public function testEditAction()
{
    $this->assertGet('product-edit', ['productId' => 1], 403);
}

/**
 * Test Edit Action
 */
 public function testEditAction()
 {
     $this->assertPost('product-edit', ['productId' => 1], ['product-name' => 'Acme Product'], 302);
 }

Spoof Authentication Role

In order to effectively test that pages are open / closed to the correct users, this library provides an easy way to make assertions using a specified role., (*7)

/**
 * Test Edit Action
 */
public function testEditAction()
{
    // Allow our Admin role
    $user = new User();
    $this->login($user);
    $this->assertGet('product-edit', ['productId' => 1], 200);

    // Disallow Anonymous users
    $this->refreshClient();
    $this->assertGet('product-edit', ['productId' => 1], 403);
}

The Versions

26/06 2014

2.2.x-dev

2.2.9999999.9999999-dev

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

26/06 2014

dev-master

9999999-dev

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

26/06 2014

v2.2.0

2.2.0.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

27/02 2014

v2.1.0

2.1.0.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

29/01 2014

v2.0.2

2.0.2.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

29/01 2014

v2.0.1

2.0.1.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

02/12 2013

v2.0.0

2.0.0.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

22/10 2013

v1.0.5

1.0.5.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

21/10 2013

v1.0.4

1.0.4.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

28/09 2013

v1.0.3

1.0.3.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

28/09 2013

v1.0.1

1.0.1.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires

 

28/09 2013

v1.0.0

1.0.0.0

Library for quick and dirty page functional testing

  Sources   Download

MIT

The Requires