2016-03-28 11:15:08 -07:00
|
|
|
<?php
|
|
|
|
require_once('src/ReadOnlyTrait.php');
|
2017-12-11 14:10:25 -08:00
|
|
|
|
|
|
|
use MichaelAChrisco\ReadOnly\ReadOnlyException;
|
|
|
|
use MichaelAChrisco\ReadOnly\ReadOnlyTrait;
|
2017-03-27 13:14:50 -07:00
|
|
|
|
2024-01-17 12:04:18 -08:00
|
|
|
class User extends Illuminate\Database\Eloquent\Model
|
|
|
|
{
|
|
|
|
use ReadOnlyTrait;
|
2016-03-28 11:15:08 -07:00
|
|
|
}
|
|
|
|
|
2024-01-17 12:04:18 -08:00
|
|
|
describe("User", function () {
|
|
|
|
context("When User calls unsupported method", function () {
|
|
|
|
describe("::create()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->create([]);
|
|
|
|
})->toThrow(new ReadOnlyException('create', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::forceCreate()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
$closure = function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->forceCreate([]);
|
|
|
|
};
|
|
|
|
expect($closure)->toThrow(new ReadOnlyException('forceCreate', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::save()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->save([]);
|
|
|
|
})->toThrow(new ReadOnlyException('save', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::update()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->update([]);
|
|
|
|
})->toThrow(new ReadOnlyException('update', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::firstOrCreate()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->firstOrCreate([]);
|
|
|
|
})->toThrow(new ReadOnlyException('firstOrCreate', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::firstOrNew()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->firstOrNew([]);
|
|
|
|
})->toThrow(new ReadOnlyException('firstOrNew', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::delete()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->delete();
|
|
|
|
})->toThrow(new ReadOnlyException('delete', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::destroy()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->destroy(1);
|
|
|
|
})->toThrow(new ReadOnlyException('destroy', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::restore()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->restore();
|
|
|
|
})->toThrow(new ReadOnlyException('restore', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::forceDelete()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->forceDelete();
|
|
|
|
})->toThrow(new ReadOnlyException('forceDelete', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::performDeleteOnModel()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->performDeleteOnModel();
|
|
|
|
})->toThrow(new ReadOnlyException('performDeleteOnModel', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::push()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->push();
|
|
|
|
})->toThrow(new ReadOnlyException('push', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::finishSave()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->finishSave([]);
|
|
|
|
})->toThrow(new ReadOnlyException('finishSave', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::performUpdate()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
$user = new User;
|
|
|
|
//TODO: Mock up
|
|
|
|
// $user = new User;
|
|
|
|
// $user->performUpdate(new Builder, []);
|
|
|
|
unset($user);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::touch()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->touch();
|
|
|
|
})->toThrow(new ReadOnlyException('touch', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::truncate()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->truncate();
|
|
|
|
})->toThrow(new ReadOnlyException('truncate', 'User'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::insert()", function () {
|
|
|
|
it("is expected to throw ReadOnlyException", function () {
|
|
|
|
expect(
|
|
|
|
function () {
|
|
|
|
$user = new User;
|
|
|
|
$user->insert();
|
|
|
|
})->toThrow(new ReadOnlyException('insert', 'User'));
|
|
|
|
});
|
|
|
|
});
|
2017-03-29 10:15:48 -07:00
|
|
|
});
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
2022-09-07 09:14:13 -07:00
|
|
|
|
|
|
|
class MockModel
|
|
|
|
{
|
2024-01-17 12:04:18 -08:00
|
|
|
public static function create(array $attributes = [])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2022-09-07 09:14:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class UserReadOnlyNotActive extends MockModel
|
|
|
|
{
|
|
|
|
use ReadOnlyTrait;
|
|
|
|
|
|
|
|
protected static function isActive(): bool
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("UserReadOnlyNotActive", function () {
|
2024-01-17 12:08:41 -08:00
|
|
|
context("When UserReadOnlyNotActive calls unsupported method and isActive is true", function () {
|
|
|
|
describe("::create()", function () {
|
|
|
|
it("expects `create()` to be toBeTruthy", function () {
|
|
|
|
$user = new UserReadOnlyNotActive;
|
|
|
|
expect($user->create([]))->toBeTruthy();
|
|
|
|
});
|
2024-01-17 12:04:18 -08:00
|
|
|
});
|
2022-09-07 09:14:13 -07:00
|
|
|
});
|
|
|
|
});
|