Skip to content

Commit

Permalink
Merge pull request #17 from jubianchi/faker
Browse files Browse the repository at this point in the history
Add Faker support
  • Loading branch information
stephpy committed Feb 7, 2013
2 parents 526edd4 + f6a87c8 commit c74d6fd
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 169 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
* master (next 1.1.0)

* Add fluent interface for controllers testing
* Compatibility break (static $kernel variable become a class variable)
* Add support for Faker (https://github.com/fzaninotto/Faker)
* Compatibility break
* static $kernel variable become a class variable
* AtoumBundle\Test\Units\Test::getRandomString() and AtoumBundle\Test\Generator\String were removed

* 1.0.0 (2012)

Expand Down
7 changes: 2 additions & 5 deletions Test/Controller/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@

abstract class ControllerTest extends WebTestCase
{
/**
* @param atoum\factory $factory factory
*/
public function __construct(atoum\factory $factory = null)
public function __construct(atoum\adapter $adapter = null, atoum\annotations\extractor $annotationExtractor = null, atoum\asserter\generator $asserterGenerator = null, atoum\test\assertion\manager $assertionManager = null, \closure $reflectionClassFactory = null)
{
parent::__construct($factory);
parent::__construct($adapter, $annotationExtractor, $asserterGenerator, $assertionManager, $reflectionClassFactory);
$this->setTestNamespace('Tests');
}
}
68 changes: 0 additions & 68 deletions Test/Generator/String.php

This file was deleted.

52 changes: 21 additions & 31 deletions Test/Units/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,35 @@

namespace atoum\AtoumBundle\Test\Units;

use atoum\AtoumBundle\Test\Generator;
use mageekguy\atoum;

abstract class Test extends atoum\test
{
/**
* @param atoum\factory $factory factory
*/
public function __construct(atoum\factory $factory = null)
public function __construct(atoum\adapter $adapter = null, atoum\annotations\extractor $annotationExtractor = null, atoum\asserter\generator $asserterGenerator = null, atoum\test\assertion\manager $assertionManager = null, \closure $reflectionClassFactory = null)
{
$this->setTestNamespace('Tests\Units');
parent::__construct($factory);

parent::__construct($adapter, $annotationExtractor, $asserterGenerator, $assertionManager, $reflectionClassFactory);
}

public function setAssertionManager(atoum\test\assertion\manager $assertionManager = null)
{
$self = $this;

$returnFaker = function($locale = 'en_US') use ($self) {
return $self->getFaker($locale);
};

parent::setAssertionManager($assertionManager)
->getAssertionManager()
->setHandler('faker', $returnFaker)
;

return $this;
}

/**
* Return a random string
*
* $this->getRandomString()
* => random alphanumeric string of random length (between 8 and 16)
*
* $this->getRandomString(32)
* => random alphanumeric string of length 32
*
* $this->getRandomString(10, Generator\String::CHARACTERS_NUMERIC)
* => random numeric string of length 10
*
* $this->getRandomString(10, Generator\String::CHARACTERS_NUMERIC + Generator\String::CHARACTERS_ALPHA_LOWER)
* => random lower case alpha numeric string of length 10
*
* $this->getRandomString(32, '0123456789ABCDEF')
* => random hexadecimal string of length 32
*
* @param integer $length
* @param integer|string $characters
*
* @return string
*/
protected function getRandomString($length = null, $characters = Generator\String::CHARACTERS_ALPHANUMERIC)
public function getFaker($locale = 'en_US')
{
return Generator\String::generate($length, $characters);
return \Faker\Factory::create($locale);
}
}
5 changes: 3 additions & 2 deletions Test/Units/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use atoum\AtoumBundle\Test\Asserters;
use mageekguy\atoum;

/**
* WebTestCase
Expand All @@ -21,9 +22,9 @@ abstract class WebTestCase extends Test
/** @var \Symfony\Component\HttpFoundation\HttpKernelInterface */
protected $kernel;

public function __construct(\mageekguy\atoum\factory $factory = null)
public function __construct(atoum\adapter $adapter = null, atoum\annotations\extractor $annotationExtractor = null, atoum\asserter\generator $asserterGenerator = null, atoum\test\assertion\manager $assertionManager = null, \closure $reflectionClassFactory = null)
{
parent::__construct($factory);
parent::__construct($adapter, $annotationExtractor, $asserterGenerator, $assertionManager, $reflectionClassFactory);

$generator = $this->getAsserterGenerator();
$test = $this;
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"email": "[email protected]"
},
{
"name": "Community contributors",
"homepage": "https://github.com/atoum/AtoumBundle/graphs/contributors"
"name": "Community contributors",
"homepage": "https://github.com/atoum/AtoumBundle/graphs/contributors"
}
],
"require": {
Expand All @@ -21,7 +21,8 @@
"symfony/finder": "2.*",
"symfony/dom-crawler": "2.*",
"symfony/css-selector": "2.*",
"atoum/atoum": "dev-master"
"atoum/atoum": "dev-master",
"fzaninotto/faker": "1.*"
},
"replace": {
"rezzza/atoum-bundle": "*",
Expand Down
59 changes: 0 additions & 59 deletions tests/units/Test/Generator/String.php

This file was deleted.

46 changes: 46 additions & 0 deletions tests/units/Test/Units/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace atoum\AtoumBundle\tests\units\Test\Units;

require_once __DIR__ . '/../../../bootstrap.php';

use mageekguy\atoum;
use mageekguy\atoum\asserter;

class Test extends atoum\test
{
public function testClass()
{
$this->testedClass->isSubclassOf('\\mageekguy\\atoum\\test');
}

public function testSetAssertionManager()
{
$this
->if($object = new \mock\atoum\AtoumBundle\Test\Units\Test())
->and($manager = new \mock\mageekguy\atoum\test\assertion\manager())
->then
->object($object->setAssertionManager($manager))->isIdenticalTo($object)
->mock($manager)
->call('setHandler')->withArguments('faker')->once()
->if($object = new \mock\atoum\AtoumBundle\Test\Units\Test())
->and($this->calling($object)->getFaker = $generator = new \mock\Faker\Generator())
->and($this->calling($generator)->__call = function() {})
->then
->variable($object->faker->{$provider = uniqid()}())
->mock($generator)
->call('__call')->withArguments($provider)->once()
;
}

public function testGetFaker()
{
$this
->if($object = new \mock\atoum\AtoumBundle\Test\Units\Test())
->then
->object($faker = $object->getFaker())->isInstanceOf('\\Faker\\Generator')
->object($object->getFaker())
->isInstanceOf('\\Faker\\Generator')
->isNotIdenticalTo($faker)
;
}
}

0 comments on commit c74d6fd

Please sign in to comment.