Skip to content

Commit

Permalink
Add units tests (#3)
Browse files Browse the repository at this point in the history
Add units tests

Test For SonataGroup and CreateUserCommand
Functions AddRoles(), RemoveRole(), AddUser(), RemoveUser().

Disable Functionnal Test
  • Loading branch information
haseo29 authored and FanchTheSystem committed May 17, 2017
1 parent 317ac36 commit bbe0dcf
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 8 deletions.
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@
"blast-project/base-entities-bundle": "^0.4"
},
"require-dev": {
"symfony/phpunit-bridge": "3.2.*"
"symfony/phpunit-bridge": "3.2.*",
"symfony/monolog-bundle": "^3.1",
"symfony/swiftmailer-bundle": "^2.5",
"sensio/framework-extra-bundle": "^3.0.2",
"twig/twig": "^1.0 || ^2.0",
"symfony/polyfill-apcu": "^1.0",
"sensio/distribution-bundle": "^5.0",
"incenteev/composer-parameter-handler": "^2.0",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"doctrine/orm": "^2.5"
},
"config": {
"sllh-composer-lint": {
Expand Down
9 changes: 3 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
<testsuite name="Unit">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="Functional">
<directory>./tests/Functional</directory>
</testsuite>
</testsuites>


<filter>
<whitelist>
<directory>./src</directory>
<directory>./</directory>
<exclude>
<directory>./Tests/</directory>
<directory>./tests/</directory>
<directory>./DataFixtures/</directory>
<directory>./Resources/</directory>
<directory>./vendor/</directory>
Expand All @@ -37,7 +34,7 @@
</filter>

<php>
<server name="KERNEL_DIR" value="tests/Resources/app/" />
<server name="KERNEL_DIR" value="tests/Resources/App/" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
</php>

Expand Down
33 changes: 33 additions & 0 deletions tests/Functional/BundleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Librinfo\SonataSyliusUserBundle\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\Container;

class BundleTest extends KernelTestCase
{

protected $container;

protected function setUp() {
static::bootKernel();

/** @var Container $container */
$this->container = self::$kernel->getContainer();
}

public function testServicesAreInitializable() {

$this->markTestIncomplete('This test has not been implemented yet.');

$serviceIds = array_filter($this->container->getServiceIds(), function ($serviceId) {
return 0 === strpos($serviceId, "sonata_sylius_user" . '.');
});

foreach ($serviceIds as $serviceId) {
$this->assertNotNull($this->container->get($serviceId));
}
}

}
2 changes: 1 addition & 1 deletion tests/Resources/autoload.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ $files = array(

$autoload = false;
foreach ($files as $file) {

if (is_file($file)) {
$autoload = include_once $file;

break;
}
}
Expand Down
59 changes: 59 additions & 0 deletions tests/Unit/CreateUserCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Librinfo\SonataSyliusUserBundle\Command\Test\Unit;

use Librinfo\SonataSyliusUserBundle\Command\CreateUserCommand;
/* * Librinfo\SonataSyliusUserBundle\Command\CreateUserCommand'
* Generated by PHPUnit_SkeletonGenerator on 2017-05-02 at 16:34:40.
*/
use PHPUnit\Framework\TestCase;

class CreateUserCommandTest extends TestCase
{

/**
* @var CreateUserCommand
*/
protected $myCommand;
protected $myConfig;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {
$this->myCommand = new CreateUserCommand();
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {

}

/**
* @covers Librinfo\SonataSyliusUserBundle\Command\CreateUserCommand::configure
* @todo Implement testConfigure().
*/
public function testConfigure() {
$this->markTestIncomplete('This test has not been implemented yet.');

$this->myCommand->configure();

$this->myConfig = $this->myCommand->getName();
/**
* @todo : check if we need to test more (or not)
*/
$this->assertContains('user', $this->myConfig);
}

public function testExecute() {

/*
* @todo : Is it really relevant to perform tests on it?
*/
}

}
212 changes: 212 additions & 0 deletions tests/Unit/SonataGroupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?php

namespace Librinfo\SonataSyliusUserBundle\Entity\Test\Unit;

use Librinfo\SonataSyliusUserBundle\Entity\SonataGroup;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
/**
* Generated by PHPUnit_SkeletonGenerator on 2017-05-10 at 17:49:31.
*/
use PHPUnit\Framework\TestCase;

class SonataGroupTest extends TestCase
{

/**
* @var SonataGroup
*/
protected $object;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {
$this->object = new SonataGroup;
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {

}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::__toString
* @todo Implement test__toString().
*/
public function test__toString() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::addRole
* @todo Implement testAddRole().
*/
public function testAddRole() {
/**
* @todo 1.appeler addRole
* 2. appeler getRoles
* 3. faire un assert pour vérifier que le role qu'on a passer a addRoles
* est bien dans le resultat de getRoles
*/
$role = 'foo';

$this->object->addRole($role);

$listRoles = $this->object->getRoles();

// we search 'foo' in uppercase because addRoles transform a string in uppercase
$this->assertContains('FOO', $listRoles);
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::getId
* @todo Implement testGetId().
*/
public function testGetId() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::getName
* @todo Implement testGetName().
*/
public function testGetName() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::hasRole
* @todo Implement testHasRole().
*/
public function testHasRole() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::getRoles
* @todo Implement testGetRoles().
*/
public function testGetRoles() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::removeRole
* @todo Implement testRemoveRole().
*/
public function testRemoveRole() {
$role = 'foo';
$role2 = 'bar';
$role3 = 'zoo';

$this->object->addRole($role);
$this->object->addRole($role2);
$this->object->addRole($role3);

$listRoles = $this->object->getRoles();

$this->object->removeRole($role2);
//we call again getRoles() for refresh the array
$listRoles = $this->object->getRoles();

$this->assertNotContains('bar', $listRoles);
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::setName
* @todo Implement testSetName().
*/
public function testSetName() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::setRoles
* @todo Implement testSetRoles().
*/
public function testSetRoles() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::addUser
* @todo Implement testAddUser().
*/
public function testAddUser() {
$this->markTestIncomplete('This test has not been implemented yet.');

$toto = 'weekend';
$user = $this->getMockForAbstractClass(AdvancedUserInterface::class);

$get = $this->object->addUser($user)->getUsers();

$this->assertNotNull($get);
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::removeUser
* @todo Implement testRemoveUser().
*/
public function testRemoveUser() {
$this->markTestIncomplete('This test has not been implemented yet.');

$toto = 'lundi matin';
$user = $this
->getMockForAbstractClass(AdvancedUserInterface::class);
$this->object->addUser($user);
$get = $this->object->getUsers();

$get = $this->object->removeUser($user);
$get = $this->object->getUsers();

$this->assertEquals(0, $get->count());
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::getUsers
* @todo Implement testGetUsers().
*/
public function testGetUsers() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::setUsers
* @todo Implement testSetUsers().
*/
public function testSetUsers() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::setId
* @todo Implement testSetId().
*/
public function testSetId() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers Librinfo\SonataSyliusUserBundle\Entity\SonataGroup::isNew
* @todo Implement testIsNew().
*/
public function testIsNew() {
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

}

0 comments on commit bbe0dcf

Please sign in to comment.