mirror of
https://github.com/michaelachrisco/ReadOnlyTraitLaravel.git
synced 2024-12-26 07:37:20 -08:00
Merge pull request #57 from michaelachrisco/56-add-context-to-kahlan
feat(spec): Testing users should have more context
This commit is contained in:
commit
276836059b
2 changed files with 179 additions and 164 deletions
|
@ -19,9 +19,19 @@ jobs:
|
||||||
- run: sudo composer self-update
|
- run: sudo composer self-update
|
||||||
- run: composer install -n --prefer-dist --no-plugins
|
- run: composer install -n --prefer-dist --no-plugins
|
||||||
- run: ./vendor/bin/kahlan -reporter=verbose
|
- run: ./vendor/bin/kahlan -reporter=verbose
|
||||||
|
build_php_version_83:
|
||||||
|
docker:
|
||||||
|
- image: cimg/php:8.3.0
|
||||||
|
working_directory: ~/ReadOnlyTraitLaravel
|
||||||
|
steps: # a set of executable commands
|
||||||
|
- checkout
|
||||||
|
- run: sudo composer self-update
|
||||||
|
- run: composer install -n --prefer-dist --no-plugins
|
||||||
|
- run: ./vendor/bin/kahlan -reporter=verbose
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
build:
|
build:
|
||||||
jobs:
|
jobs:
|
||||||
- build_php_version_81
|
- build_php_version_81
|
||||||
- build_php_version_82
|
- build_php_version_82
|
||||||
|
- build_php_version_83
|
||||||
|
|
|
@ -4,130 +4,132 @@ 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 () {
|
||||||
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->create([]);
|
$user->create([]);
|
||||||
})->toThrow(new ReadOnlyException('create', 'User'));
|
})->toThrow(new ReadOnlyException('create', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::forceCreate()", function(){
|
describe("::forceCreate()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
$closure = function(){
|
$closure = function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->forceCreate([]);
|
$user->forceCreate([]);
|
||||||
};
|
};
|
||||||
expect($closure)->toThrow(new ReadOnlyException('forceCreate', 'User'));
|
expect($closure)->toThrow(new ReadOnlyException('forceCreate', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::save()", function(){
|
describe("::save()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->save([]);
|
$user->save([]);
|
||||||
})->toThrow(new ReadOnlyException('save', 'User'));
|
})->toThrow(new ReadOnlyException('save', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::update()", function(){
|
describe("::update()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->update([]);
|
$user->update([]);
|
||||||
})->toThrow(new ReadOnlyException('update', 'User'));
|
})->toThrow(new ReadOnlyException('update', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::firstOrCreate()", function(){
|
describe("::firstOrCreate()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->firstOrCreate([]);
|
$user->firstOrCreate([]);
|
||||||
})->toThrow(new ReadOnlyException('firstOrCreate', 'User'));
|
})->toThrow(new ReadOnlyException('firstOrCreate', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::firstOrNew()", function(){
|
describe("::firstOrNew()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->firstOrNew([]);
|
$user->firstOrNew([]);
|
||||||
})->toThrow(new ReadOnlyException('firstOrNew', 'User'));
|
})->toThrow(new ReadOnlyException('firstOrNew', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::delete()", function(){
|
describe("::delete()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->delete();
|
$user->delete();
|
||||||
})->toThrow(new ReadOnlyException('delete', 'User'));
|
})->toThrow(new ReadOnlyException('delete', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::destroy()", function(){
|
describe("::destroy()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->destroy(1);
|
$user->destroy(1);
|
||||||
})->toThrow(new ReadOnlyException('destroy', 'User'));
|
})->toThrow(new ReadOnlyException('destroy', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::restore()", function(){
|
describe("::restore()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->restore();
|
$user->restore();
|
||||||
})->toThrow(new ReadOnlyException('restore', 'User'));
|
})->toThrow(new ReadOnlyException('restore', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::forceDelete()", function(){
|
describe("::forceDelete()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->forceDelete();
|
$user->forceDelete();
|
||||||
})->toThrow(new ReadOnlyException('forceDelete', 'User'));
|
})->toThrow(new ReadOnlyException('forceDelete', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::performDeleteOnModel()", function(){
|
describe("::performDeleteOnModel()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->performDeleteOnModel();
|
$user->performDeleteOnModel();
|
||||||
})->toThrow(new ReadOnlyException('performDeleteOnModel', 'User'));
|
})->toThrow(new ReadOnlyException('performDeleteOnModel', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::push()", function(){
|
describe("::push()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->push();
|
$user->push();
|
||||||
})->toThrow(new ReadOnlyException('push', 'User'));
|
})->toThrow(new ReadOnlyException('push', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::finishSave()", function(){
|
describe("::finishSave()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->finishSave([]);
|
$user->finishSave([]);
|
||||||
})->toThrow(new ReadOnlyException('finishSave', 'User'));
|
})->toThrow(new ReadOnlyException('finishSave', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::performUpdate()", function(){
|
describe("::performUpdate()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
//TODO: Mock up
|
//TODO: Mock up
|
||||||
// $user = new User;
|
// $user = new User;
|
||||||
|
@ -135,33 +137,34 @@ describe("User", function() {
|
||||||
unset($user);
|
unset($user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::touch()", function(){
|
describe("::touch()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->touch();
|
$user->touch();
|
||||||
})->toThrow(new ReadOnlyException('touch', 'User'));
|
})->toThrow(new ReadOnlyException('touch', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::truncate()", function(){
|
describe("::truncate()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->truncate();
|
$user->truncate();
|
||||||
})->toThrow(new ReadOnlyException('truncate', 'User'));
|
})->toThrow(new ReadOnlyException('truncate', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("::insert()", function(){
|
describe("::insert()", function () {
|
||||||
it("is expected to throw ReadOnlyException", function() {
|
it("is expected to throw ReadOnlyException", function () {
|
||||||
expect(
|
expect(
|
||||||
function(){
|
function () {
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->insert();
|
$user->insert();
|
||||||
})->toThrow(new ReadOnlyException('insert', 'User'));
|
})->toThrow(new ReadOnlyException('insert', 'User'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
class MockModel
|
class MockModel
|
||||||
|
@ -183,10 +186,12 @@ class UserReadOnlyNotActive extends MockModel
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("UserReadOnlyNotActive", function () {
|
describe("UserReadOnlyNotActive", function () {
|
||||||
|
context("When UserReadOnlyNotActive calls unsupported method and isActive is true", 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