mirror of
https://github.com/michaelachrisco/ReadOnlyTraitLaravel.git
synced 2024-10-31 21:33:23 -07:00
feat(spec): Testing users should have more context
This commit is contained in:
parent
bb92b3f675
commit
98bbdf71f4
1 changed files with 166 additions and 163 deletions
|
@ -4,172 +4,175 @@ require_once('src/ReadOnlyTrait.php');
|
||||||
use MichaelAChrisco\ReadOnly\ReadOnlyException;
|
use MichaelAChrisco\ReadOnly\ReadOnlyException;
|
||||||
use MichaelAChrisco\ReadOnly\ReadOnlyTrait;
|
use MichaelAChrisco\ReadOnly\ReadOnlyTrait;
|
||||||
|
|
||||||
class User extends Illuminate\Database\Eloquent\Model {
|
class User extends Illuminate\Database\Eloquent\Model
|
||||||
use ReadOnlyTrait;
|
{
|
||||||
|
use ReadOnlyTrait;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("User", function() {
|
describe("User", function () {
|
||||||
describe("::create()", function(){
|
context("When User calls unsupported method", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::create()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->create([]);
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('create', 'User'));
|
$user->create([]);
|
||||||
});
|
})->toThrow(new ReadOnlyException('create', 'User'));
|
||||||
});
|
});
|
||||||
describe("::forceCreate()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::forceCreate()", function () {
|
||||||
$closure = function(){
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
$user = new User;
|
$closure = function () {
|
||||||
$user->forceCreate([]);
|
$user = new User;
|
||||||
};
|
$user->forceCreate([]);
|
||||||
expect($closure)->toThrow(new ReadOnlyException('forceCreate', 'User'));
|
};
|
||||||
});
|
expect($closure)->toThrow(new ReadOnlyException('forceCreate', 'User'));
|
||||||
});
|
});
|
||||||
describe("::save()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::save()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->save([]);
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('save', 'User'));
|
$user->save([]);
|
||||||
});
|
})->toThrow(new ReadOnlyException('save', 'User'));
|
||||||
});
|
});
|
||||||
describe("::update()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::update()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->update([]);
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('update', 'User'));
|
$user->update([]);
|
||||||
});
|
})->toThrow(new ReadOnlyException('update', 'User'));
|
||||||
});
|
});
|
||||||
describe("::firstOrCreate()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::firstOrCreate()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->firstOrCreate([]);
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('firstOrCreate', 'User'));
|
$user->firstOrCreate([]);
|
||||||
});
|
})->toThrow(new ReadOnlyException('firstOrCreate', 'User'));
|
||||||
});
|
});
|
||||||
describe("::firstOrNew()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::firstOrNew()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->firstOrNew([]);
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('firstOrNew', 'User'));
|
$user->firstOrNew([]);
|
||||||
});
|
})->toThrow(new ReadOnlyException('firstOrNew', 'User'));
|
||||||
});
|
});
|
||||||
describe("::delete()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::delete()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->delete();
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('delete', 'User'));
|
$user->delete();
|
||||||
});
|
})->toThrow(new ReadOnlyException('delete', 'User'));
|
||||||
});
|
});
|
||||||
describe("::destroy()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::destroy()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->destroy(1);
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('destroy', 'User'));
|
$user->destroy(1);
|
||||||
});
|
})->toThrow(new ReadOnlyException('destroy', 'User'));
|
||||||
});
|
});
|
||||||
describe("::restore()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::restore()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->restore();
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('restore', 'User'));
|
$user->restore();
|
||||||
});
|
})->toThrow(new ReadOnlyException('restore', 'User'));
|
||||||
});
|
});
|
||||||
describe("::forceDelete()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::forceDelete()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->forceDelete();
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('forceDelete', 'User'));
|
$user->forceDelete();
|
||||||
});
|
})->toThrow(new ReadOnlyException('forceDelete', 'User'));
|
||||||
});
|
});
|
||||||
describe("::performDeleteOnModel()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::performDeleteOnModel()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->performDeleteOnModel();
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('performDeleteOnModel', 'User'));
|
$user->performDeleteOnModel();
|
||||||
});
|
})->toThrow(new ReadOnlyException('performDeleteOnModel', 'User'));
|
||||||
});
|
});
|
||||||
describe("::push()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::push()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->push();
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('push', 'User'));
|
$user->push();
|
||||||
});
|
})->toThrow(new ReadOnlyException('push', 'User'));
|
||||||
});
|
});
|
||||||
describe("::finishSave()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::finishSave()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->finishSave([]);
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('finishSave', 'User'));
|
$user->finishSave([]);
|
||||||
});
|
})->toThrow(new ReadOnlyException('finishSave', 'User'));
|
||||||
});
|
});
|
||||||
describe("::performUpdate()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::performUpdate()", function () {
|
||||||
$user = new User;
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
//TODO: Mock up
|
$user = new User;
|
||||||
// $user = new User;
|
//TODO: Mock up
|
||||||
// $user->performUpdate(new Builder, []);
|
// $user = new User;
|
||||||
unset($user);
|
// $user->performUpdate(new Builder, []);
|
||||||
});
|
unset($user);
|
||||||
});
|
});
|
||||||
describe("::touch()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::touch()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->touch();
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('touch', 'User'));
|
$user->touch();
|
||||||
});
|
})->toThrow(new ReadOnlyException('touch', 'User'));
|
||||||
});
|
});
|
||||||
describe("::truncate()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::truncate()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->truncate();
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('truncate', 'User'));
|
$user->truncate();
|
||||||
});
|
})->toThrow(new ReadOnlyException('truncate', 'User'));
|
||||||
});
|
});
|
||||||
describe("::insert()", function(){
|
});
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
describe("::insert()", function () {
|
||||||
expect(
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
function(){
|
expect(
|
||||||
$user = new User;
|
function () {
|
||||||
$user->insert();
|
$user = new User;
|
||||||
})->toThrow(new ReadOnlyException('insert', 'User'));
|
$user->insert();
|
||||||
});
|
})->toThrow(new ReadOnlyException('insert', 'User'));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
class MockModel
|
class MockModel
|
||||||
{
|
{
|
||||||
public static function create(array $attributes = [])
|
public static function create(array $attributes = [])
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserReadOnlyNotActive extends MockModel
|
class UserReadOnlyNotActive extends MockModel
|
||||||
|
@ -184,9 +187,9 @@ class UserReadOnlyNotActive extends MockModel
|
||||||
|
|
||||||
describe("UserReadOnlyNotActive", function () {
|
describe("UserReadOnlyNotActive", function () {
|
||||||
describe("::create()", function () {
|
describe("::create()", function () {
|
||||||
it("expects `create()` to be toBeTruthy", function() {
|
it("expects `create()` to be toBeTruthy", function () {
|
||||||
$user = new UserReadOnlyNotActive;
|
$user = new UserReadOnlyNotActive;
|
||||||
expect($user->create([]))->toBeTruthy();
|
expect($user->create([]))->toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue