Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended bakery test to add Test Scope #919

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/sprinkles/account/factories/Users.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* UserFrosting (http://www.userfrosting.com)
*
Expand All @@ -11,12 +12,12 @@
* General factory for the User Model
*/
$fm->define('UserFrosting\Sprinkle\Account\Database\Models\User')->setDefinitions([
'user_name' => Faker::unique()->firstNameMale(),
'first_name' => Faker::firstNameMale(),
'last_name' => Faker::firstNameMale(),
'email' => Faker::unique()->email(),
'locale' => 'en_US',
'user_name' => Faker::unique()->userName(),
'first_name' => Faker::firstName(),
'last_name' => Faker::lastName(),
'email' => Faker::unique()->email(),
'locale' => 'en_US',
'flag_verified' => 1,
'flag_enabled' => 1,
'password' => Faker::password()
'flag_enabled' => 1,
'password' => Faker::password()
]);
3 changes: 2 additions & 1 deletion app/sprinkles/account/tests/Unit/HasherTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

/**
* UserFrosting (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
*/

namespace UserFrosting\Tests\Unit;
namespace UserFrosting\Sprinkle\Account\Tests\Unit;

use UserFrosting\Sprinkle\Account\Authenticate\Hasher;
use UserFrosting\Tests\TestCase;
Expand Down
21 changes: 11 additions & 10 deletions app/sprinkles/account/tests/Unit/PDOStorageTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

/**
* UserFrosting (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
*/

namespace UserFrosting\Tests\Unit;
namespace UserFrosting\Sprinkle\Account\Tests\Unit;

use Birke\Rememberme\Storage\StorageInterface;
use Carbon\Carbon;
Expand Down Expand Up @@ -99,10 +100,10 @@ public function testCleanAllTripletsRemovesAllEntriesWithMatchingCredentialsFrom
{
$this->insertTestData();
$persistence = new Persistence([
'user_id' => $this->testUser->id,
'token' => 'dummy',
'user_id' => $this->testUser->id,
'token' => 'dummy',
'persistent_token' => 'dummy',
'expires_at' => null
'expires_at' => null
]);
$persistence->save();
$this->storage->cleanAllTriplets($this->testUser->id);
Expand All @@ -122,10 +123,10 @@ public function testCleanExpiredTokens()
{
$this->insertTestData();
$persistence = new Persistence([
'user_id' => $this->testUser->id,
'token' => 'dummy',
'user_id' => $this->testUser->id,
'token' => 'dummy',
'persistent_token' => 'dummy',
'expires_at' => Carbon::now()->subHour(1)
'expires_at' => Carbon::now()->subHour(1)
]);
$persistence->save();
$this->assertEquals(2, Persistence::count());
Expand All @@ -140,10 +141,10 @@ public function testCleanExpiredTokens()
protected function insertTestData()
{
$persistence = new Persistence([
'user_id' => $this->testUser->id,
'token' => $this->validDBToken,
'user_id' => $this->testUser->id,
'token' => $this->validDBToken,
'persistent_token' => $this->validDBPersistentToken,
'expires_at' => $this->expire
'expires_at' => $this->expire
]);
$persistence->save();

Expand Down
66 changes: 45 additions & 21 deletions app/sprinkles/account/tests/Unit/RegistrationTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

/**
* UserFrosting (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
*/

namespace UserFrosting\Tests\Unit;
namespace UserFrosting\Sprinkle\Account\Tests\Unit;

use Mockery as m;
use UserFrosting\Tests\TestCase;
Expand Down Expand Up @@ -57,11 +58,11 @@ public function testNormalRegistration()

// Genereate user data
$fakeUserData = [
'user_name' => 'FooBar',
'first_name' => 'Foo',
'last_name' => 'Bar',
'email' => 'Foo@Bar.com',
'password' => 'FooBarFooBar123'
'user_name' => 'FooBar',
'first_name' => 'Foo',
'last_name' => 'Bar',
'email' => 'Foo@Bar.com',
'password' => 'FooBarFooBar123'
];

// Get class
Expand All @@ -77,14 +78,29 @@ public function testNormalRegistration()

// We try to register the same user again. Should throw an error
$registration = new Registration($this->ci, $fakeUserData);
$this->expectException(HttpException::class);
$validation = $registration->validate();
// $this->expectException(HttpException::class);
// Commenting expectExcaption as this causes a failure, even though the exception is raised.
$exception_thrown = false;
try {
$validation = $registration->validate();
} catch (HttpException $e) {
$exception_thrown = true;
}
$this->assertTrue($exception_thrown);

// Should throw email error if we change the username
$fakeUserData['user_name'] = 'BarFoo';
$registration = new Registration($this->ci, $fakeUserData);
$this->expectException(HttpException::class);
$validation = $registration->validate();
// $this->expectException(HttpException::class);
// Commenting expectExcaption as this causes a failure, even though the exception is raised.
$exception_thrown = false;
try {
$validation = $registration->validate();
} catch (HttpException $e) {
// $this->expectException(HttpException::class);
$exception_thrown = true;
}
$this->assertTrue($exception_thrown);
}

/**
Expand All @@ -96,11 +112,11 @@ public function testValidation()
$this->refreshDatabase();

$registration = new Registration($this->ci, [
'user_name' => 'FooBar',
'first_name' => 'Foo',
'last_name' => 'Bar',
'email' => 'Foo@Bar.com',
'password' => 'FooBarFooBar123'
'user_name' => 'FooBar',
'first_name' => 'Foo',
'last_name' => 'Bar',
'email' => 'Foo@Bar.com',
'password' => 'FooBarFooBar123'
]);

// Validate user. Shouldn't tell us the username is already in use since we reset the database
Expand All @@ -117,15 +133,23 @@ public function testMissingFields()
$this->refreshDatabase();

$registration = new Registration($this->ci, [
'user_name' => 'FooBar',
'user_name' => 'FooBar',
//'first_name' => 'Foo',
'last_name' => 'Bar',
'email' => 'Foo@Bar.com',
'password' => 'FooBarFooBar123'
'last_name' => 'Bar',
'email' => 'Foo@Bar.com',
'password' => 'FooBarFooBar123'
]);

// Validate user. Shouldn't tell us the username is already in use since we reset the database
$this->expectException(HttpException::class);
$validation = $registration->validate();
// $this->expectException(HttpException::class);
// Commenting expectExcaption as this causes a failure, even though the exception is raised.
$exception_thrown = false;
try {
$validation = $registration->validate();
} catch (HttpException $e) {
// $this->expectException(HttpException::class);
$exception_thrown = true;
}
$this->assertTrue($exception_thrown);
}
}
22 changes: 19 additions & 3 deletions app/system/Bakery/Command/Test.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* UserFrosting (http://www.userfrosting.com)
*
Expand All @@ -11,6 +12,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use UserFrosting\System\Bakery\BaseCommand;

/**
Expand All @@ -32,9 +34,10 @@ class Test extends BaseCommand
protected function configure()
{
$this->setName('test')
->addOption('coverage', 'c', InputOption::VALUE_NONE, 'Generate code coverage report in HTML format. Will be saved in _meta/coverage')
->setDescription('Run tests')
->setHelp('Run php unit tests');
->addOption('coverage', 'c', InputOption::VALUE_NONE, 'Generate code coverage report in HTML format. Will be saved in _meta/coverage')
->addArgument('testscope', InputArgument::OPTIONAL, 'Test Scope :Sprinkle, Class and Medhod Name (Optional): ')
->setDescription('Run tests, Optionally sprcific Sprinkle, Class and Medhod ')
->setHelp('Run php unit tests, Optionally specif Sprinkle, Class and Medhod name');
}

/**
Expand All @@ -50,6 +53,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
$command .= ' -v';
}

$testscope = $input->getArgument('testscope');
if ($testscope) {
$slashes = " \\\\ ";
if (strpos($testscope, "\\") !== false) {
$this->io->writeln("> <comment>Executing Specified Test Scope $testscope</comment>");
$testscope1 = str_replace("\\", trim($slashes), $testscope);
$command .= " --filter='UserFrosting" . trim($slashes) . "Sprinkle" . trim($slashes) . $testscope1 . "'";
} else {
$this->io->writeln("> <comment>Executing all tests in Sprinkle $testscope</comment>");
$command .= " --filter='UserFrosting" . trim($slashes) . "Sprinkle" . trim($slashes) . $testscope . trim($slashes) . "Tests" . trim($slashes) . "' ";
}
}

// Add coverage report
if ($input->getOption('coverage')) {
$command .= ' --coverage-html _meta/coverage';
Expand Down
95 changes: 95 additions & 0 deletions docker-compose-testdb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: "3.2"
services:
php:
image: regsevak.com/php
restart: unless-stopped
tty: true
build:
context: ./docker/php
environment:
- DB_DRIVER=mysql
- DB_HOST=mysqlprod
- DB_PORT=3306
- DB_NAME=uf42chinmaya_dbdocker
- DB_USER=docker
- DB_PASSWORD=secret
- DB_TEST_DRIVER=mysql
- DB_TEST_HOST=mysqltest
- DB_TEST_PORT=3306
- DB_TEST_NAME=uf42chinmaya_test_dbdocker
- DB_TEST_USER=docker
- DB_TEST_PASSWORD=secret
- TEST_DB=test_chinmaya
volumes:
- .:/app
networks:
- backend
nginx:
restart: unless-stopped
tty: true
ports:
- "8580:80"
- "8581:443"
build:
context: ./docker/nginx
volumes:
- .:/app
depends_on:
- php
- mysqlprod
- mysqltest
networks:
- frontend
- backend
mysqlprod:
image: mysql:5.7
networks:
- backend
environment:
- MYSQL_DATABASE=uf42chinmaya_dbdocker
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_USER=docker
- MYSQL_PASSWORD=secret
ports:
- 8571:3306
volumes:
- uf42chinmaya-db:/var/lib/mysql
mysqltest:
image: mysql:5.7
networks:
- backend
environment:
- MYSQL_DATABASE=uf42chinmaya_test_dbdocker
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_USER=docker
- MYSQL_PASSWORD=secret
ports:
- 8572:3306
volumes:
- uf42chinmaya-testdb:/var/lib/mysql

composer:
image: composer/composer
volumes:
- .:/app
working_dir: /app
command: -V

node:
image: node:alpine
build:
context: ./docker/node
volumes:
- .:/app
working_dir: /app/build
command: npm run uf-assets-install

volumes:
uf42chinmaya-db:
driver: local
uf42chinmaya-testdb:
driver: local

networks:
frontend:
backend:
Loading