Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlap committed Jun 28, 2017
1 parent 0dc6a4f commit b8813e8
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 17 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"php" : "~5.6|~7.0"
},
"require-dev": {
"phpunit/phpunit" : "~4.0||~5.0",
"orchestra/testbench": "~3.0",
"orchestra/database": "~3.1",
"phpunit/phpunit": "~4.0||~5.0",
"squizlabs/php_codesniffer": "^2.3"
},
"autoload": {
Expand All @@ -30,7 +32,7 @@
},
"autoload-dev": {
"psr-4": {
"Victorlap\\Approvable\\": "tests"
"Victorlap\\Approvable\\Tests\\": "tests"
}
},
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand All @@ -11,7 +12,7 @@
>
<testsuites>
<testsuite name="Approvable Test Suite">
<directory suffix=".php">./tests/</directory>
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
20 changes: 20 additions & 0 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Victorlap\Approvable\Tests;

use Victorlap\Approvable\Tests\Models\UserCanApprove;
use Victorlap\Approvable\Tests\Models\UserCannotApprove;

class BaseTests extends TestCase
{

public function testApproverCanCreate() {
$user = UserCanApprove::create(['name' => 'John Doe', 'email' => 'john@doe.com']);
$this->assertTrue($user->exists);
}

public function testRegularCanCreate() {
$user = UserCannotApprove::create(['name' => 'John Doe', 'email' => 'john2@doe.com']);
$this->assertTrue($user->exists);
}
}
14 changes: 0 additions & 14 deletions tests/ExampleTest.php

This file was deleted.

20 changes: 20 additions & 0 deletions tests/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Victorlap\Approvable\Tests\Models;

use Illuminate\Database\Eloquent\Model;
use Victorlap\Approvable\Approvable;

class User extends Model
{
use Approvable;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'users';

protected $fillable = ['name'];
}
12 changes: 12 additions & 0 deletions tests/Models/UserCanApprove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Victorlap\Approvable\Tests\Models;


class UserCanApprove extends User
{
protected function currentUserCanApprove()
{
return true;
}
}
12 changes: 12 additions & 0 deletions tests/Models/UserCannotApprove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Victorlap\Approvable\Tests\Models;


class UserCannotApprove extends User
{
protected function currentUserCanApprove()
{
return false;
}
}
47 changes: 47 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Victorlap\Approvable\Tests;

use Orchestra\Testbench\TestCase as Orchestra;
use Victorlap\Approvable\ApprovableServiceProvider;

class TestCase extends Orchestra
{

/**
* Setup the test environment.
*
* @return void
*/
public function setUp()
{
parent::setUp();

$this->artisan('migrate', ['--database' => 'testing']);
}

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// set up database configuration
$app['config']->set('database.default', 'testing');
}

/**
* Get Approvable package providers.
*
* @return array
*/
protected function getPackageProviders($app)
{
return [
TestServiceProvider::class,
ApprovableServiceProvider::class,
];
}
}
19 changes: 19 additions & 0 deletions tests/TestServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: victor
* Date: 12-2-17
* Time: 20:53
*/

namespace Victorlap\Approvable\Tests;


class TestServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
$this->loadMigrationsFrom(realpath(__DIR__.'/database/migrations/migrations'));
$this->loadMigrationsFrom(realpath(__DIR__.'/../migrations'));
}
}
35 changes: 35 additions & 0 deletions tests/database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}

0 comments on commit b8813e8

Please sign in to comment.