Skip to content

Commit

Permalink
added unit tests for different validators
Browse files Browse the repository at this point in the history
added composer self-update for travis
  • Loading branch information
kokspflanze committed May 29, 2015
1 parent db4390c commit 7e128c8
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ matrix:
- php: hhvm-nightly

before_script:
- composer self-update
- composer update --prefer-source --dev

script:
Expand Down
74 changes: 74 additions & 0 deletions tests/PServerCMSTest/Validator/StriposExistsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php


namespace PServerCMSTest\Validator;


use PServerCMSTest\Util\TestBase;

class StriposExistsTest extends TestBase
{
/** @var string */
protected $className = '\PServerCMS\Validator\StriposExists';

public function testIsValid()
{
$config = [
'pserver' => [
'blacklisted' => [
'email' => [
'foo.bar'
],
],
],
];
$this->serviceManager->setService('Config', $config);

$class = $this->getClass();

$class->__construct($this->serviceManager, $class::TYPE_EMAIL);

$this->assertTrue($class->isValid('foo@bar.sucks'));
$this->assertEmpty($class->getMessages());
}

public function testIsValidFalse()
{
$config = [
'pserver' => [
'blacklisted' => [
'email' => [
'foo.bar'
],
],
],
];
$this->serviceManager->setService('Config', $config);

$class = $this->getClass();

$class->__construct($this->serviceManager, $class::TYPE_EMAIL);

$this->assertFalse($class->isValid('bar.sucks@foo.bar'));
$this->assertNotEmpty($class->getMessages());
}


/**
* @return \PServerCMS\Validator\StriposExists|\PHPUnit_Framework_MockObject_MockObject
*/
protected function getClass()
{
if (!$this->class) {
/** @var \Zend\ServiceManager\ServiceManagerAwareInterface $class */
$class = $this->getMockBuilder($this->className)
->disableOriginalConstructor()
->setMethods($this->getMockedMethodList())
->getMock();

$this->class = $class;
}

return $this->class;
}
}
70 changes: 70 additions & 0 deletions tests/PServerCMSTest/Validator/UserNameBackendNotExistsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php


namespace PServerCMSTest\Validator;


use PServerCMSTest\Util\TestBase;

class UserNameBackendNotExistsTest extends TestBase
{
/** @var string */
protected $className = '\PServerCMS\Validator\UserNameBackendNotExists';

public function testIsValid()
{
$gameMock = $this->getMockBuilder('\GameBackend\DataService\Mocking')
->disableOriginalConstructor()
->setMethods(['isUserNameExists'])
->getMock();

$gameMock->expects($this->any())
->method('isUserNameExists')
->willReturn(false);

$this->serviceManager->setService('gamebackend_dataservice', $gameMock);
$class = $this->getClass();

$result = $class->isValid('foobar');
$this->assertTrue($result);
$this->assertEmpty($class->getMessages());
}

public function testIsValidFalse()
{
$gameMock = $this->getMockBuilder('\GameBackend\DataService\Mocking')
->disableOriginalConstructor()
->setMethods(['isUserNameExists'])
->getMock();

$gameMock->expects($this->any())
->method('isUserNameExists')
->willReturn(true);

$this->serviceManager->setService('gamebackend_dataservice', $gameMock);
$class = $this->getClass();

$result = $class->isValid('foobar');

$this->assertFalse($result);
$this->assertNotEmpty($class->getMessages());
}

/**
* @return \PServerCMS\Validator\UserNameBackendNotExists|\PHPUnit_Framework_MockObject_MockObject
*/
protected function getClass()
{
if (!$this->class) {
/** @var \Zend\ServiceManager\ServiceManagerAwareInterface $class */
$class = $this->getMockBuilder($this->className)
->setConstructorArgs([$this->serviceManager])
->setMethods($this->getMockedMethodList())
->getMock();

$this->class = $class;
}

return $this->class;
}
}

0 comments on commit 7e128c8

Please sign in to comment.