Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Spatie\Permission\Tests; use Illuminate\Support\Facades\Artisan; use Illu..

Decoded Output download

<?php
 namespace Spatie\Permission\Tests; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Spatie\Permission\Contracts\Permission; use Spatie\Permission\Contracts\Role; use Spatie\Permission\Exceptions\PermissionDoesNotExist; use Spatie\Permission\PermissionRegistrar; use Spatie\Permission\Tests\TestModels\User; class CacheTest extends TestCase { protected $cache_init_count = 0; protected $cache_load_count = 0; protected $cache_run_count = 2; protected $registrar; protected function setUp() : void { parent::setUp(); $this->registrar = app(PermissionRegistrar::class); $this->registrar->forgetCachedPermissions(); DB::connection()->enableQueryLog(); $cacheStore = $this->registrar->getCacheStore(); switch (true) { case $cacheStore instanceof \Illuminate\Cache\DatabaseStore: $this->cache_init_count = 1; $this->cache_load_count = 1; default: } } public function it_can_cache_the_permissions() { $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_creating_a_permission() { app(Permission::class)->create(array("name" => "new")); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_updating_a_permission() { $permission = app(Permission::class)->create(array("name" => "new")); $permission->name = "other name"; $permission->save(); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_creating_a_role() { app(Role::class)->create(array("name" => "new")); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_updating_a_role() { $role = app(Role::class)->create(array("name" => "new")); $role->name = "other name"; $role->save(); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function removing_a_permission_from_a_user_should_not_flush_the_cache() { $this->testUser->givePermissionTo("edit-articles"); $this->registrar->getPermissions(); $this->testUser->revokePermissionTo("edit-articles"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount(0); } public function removing_a_role_from_a_user_should_not_flush_the_cache() { $this->testUser->assignRole("testRole"); $this->registrar->getPermissions(); $this->testUser->removeRole("testRole"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount(0); } public function it_flushes_the_cache_when_removing_a_role_from_a_permission() { $this->testUserPermission->assignRole("testRole"); $this->registrar->getPermissions(); $this->testUserPermission->removeRole("testRole"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_assign_a_permission_to_a_role() { $this->testUserRole->givePermissionTo("edit-articles"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function user_creation_should_not_flush_the_cache() { $this->registrar->getPermissions(); User::create(array("email" => "new")); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount(0); } public function it_flushes_the_cache_when_giving_a_permission_to_a_role() { $this->testUserRole->givePermissionTo($this->testUserPermission); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function has_permission_to_should_use_the_cache() { $this->testUserRole->givePermissionTo(array("edit-articles", "edit-news", "Edit News")); $this->testUser->assignRole("testRole"); $this->testUser->loadMissing("roles", "permissions"); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("edit-articles")); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("edit-news")); $this->assertQueryCount(0); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("edit-articles")); $this->assertQueryCount(0); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("Edit News")); $this->assertQueryCount(0); } public function the_cache_should_differentiate_by_guard_name() { $this->expectException(PermissionDoesNotExist::class); $this->testUserRole->givePermissionTo(array("edit-articles", "web")); $this->testUser->assignRole("testRole"); $this->testUser->loadMissing("roles", "permissions"); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("edit-articles", "web")); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); $this->resetQueryCount(); $this->assertFalse($this->testUser->hasPermissionTo("edit-articles", "admin")); $this->assertQueryCount(1); } public function get_all_permissions_should_use_the_cache() { $this->testUserRole->givePermissionTo($expected = array("edit-articles", "edit-news")); $this->testUser->assignRole("testRole"); $this->testUser->loadMissing("roles.permissions", "permissions"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); $this->resetQueryCount(); $actual = $this->testUser->getAllPermissions()->pluck("name")->sort()->values(); $this->assertEquals($actual, collect($expected)); $this->assertQueryCount(0); } public function get_all_permissions_should_not_over_hydrate_roles() { $this->testUserRole->givePermissionTo(array("edit-articles", "edit-news")); $permissions = $this->registrar->getPermissions(); $roles = $permissions->flatMap->roles; $this->assertSame($roles[0], $roles[1]); } public function it_can_reset_the_cache_with_artisan_command() { Artisan::call("permission:create-permission", array("name" => "new-permission")); $this->assertCount(1, \Spatie\Permission\Models\Permission::where("name", "new-permission")->get()); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); Artisan::call("permission:cache-reset"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } protected function assertQueryCount(int $expected) { $this->assertCount($expected, DB::getQueryLog()); } protected function resetQueryCount() { DB::flushQueryLog(); } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Spatie\Permission\Tests; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Spatie\Permission\Contracts\Permission; use Spatie\Permission\Contracts\Role; use Spatie\Permission\Exceptions\PermissionDoesNotExist; use Spatie\Permission\PermissionRegistrar; use Spatie\Permission\Tests\TestModels\User; class CacheTest extends TestCase { protected $cache_init_count = 0; protected $cache_load_count = 0; protected $cache_run_count = 2; protected $registrar; protected function setUp() : void { parent::setUp(); $this->registrar = app(PermissionRegistrar::class); $this->registrar->forgetCachedPermissions(); DB::connection()->enableQueryLog(); $cacheStore = $this->registrar->getCacheStore(); switch (true) { case $cacheStore instanceof \Illuminate\Cache\DatabaseStore: $this->cache_init_count = 1; $this->cache_load_count = 1; default: } } public function it_can_cache_the_permissions() { $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_creating_a_permission() { app(Permission::class)->create(array("\156\141\x6d\145" => "\156\x65\x77")); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_updating_a_permission() { $permission = app(Permission::class)->create(array("\156\141\x6d\x65" => "\156\145\x77")); $permission->name = "\157\164\x68\145\x72\x20\156\x61\155\x65"; $permission->save(); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_creating_a_role() { app(Role::class)->create(array("\x6e\141\x6d\x65" => "\156\145\167")); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_updating_a_role() { $role = app(Role::class)->create(array("\x6e\x61\155\145" => "\156\x65\167")); $role->name = "\x6f\164\150\x65\x72\x20\x6e\x61\x6d\x65"; $role->save(); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function removing_a_permission_from_a_user_should_not_flush_the_cache() { $this->testUser->givePermissionTo("\x65\x64\151\164\x2d\x61\x72\164\x69\143\x6c\145\x73"); $this->registrar->getPermissions(); $this->testUser->revokePermissionTo("\x65\144\x69\x74\x2d\141\x72\x74\151\143\x6c\x65\x73"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount(0); } public function removing_a_role_from_a_user_should_not_flush_the_cache() { $this->testUser->assignRole("\x74\x65\163\164\122\157\154\145"); $this->registrar->getPermissions(); $this->testUser->removeRole("\x74\x65\163\x74\122\157\154\x65"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount(0); } public function it_flushes_the_cache_when_removing_a_role_from_a_permission() { $this->testUserPermission->assignRole("\x74\x65\x73\x74\122\157\154\145"); $this->registrar->getPermissions(); $this->testUserPermission->removeRole("\164\145\163\164\122\x6f\154\145"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function it_flushes_the_cache_when_assign_a_permission_to_a_role() { $this->testUserRole->givePermissionTo("\145\144\151\x74\55\x61\x72\x74\x69\143\x6c\145\163"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function user_creation_should_not_flush_the_cache() { $this->registrar->getPermissions(); User::create(array("\145\x6d\x61\151\154" => "\x6e\145\x77")); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount(0); } public function it_flushes_the_cache_when_giving_a_permission_to_a_role() { $this->testUserRole->givePermissionTo($this->testUserPermission); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } public function has_permission_to_should_use_the_cache() { $this->testUserRole->givePermissionTo(array("\145\x64\151\x74\x2d\x61\162\x74\151\x63\154\145\x73", "\x65\x64\151\164\55\x6e\x65\x77\x73", "\x45\x64\151\x74\40\116\145\167\x73")); $this->testUser->assignRole("\x74\145\163\164\122\x6f\154\x65"); $this->testUser->loadMissing("\x72\x6f\x6c\145\x73", "\x70\x65\162\x6d\x69\x73\x73\151\157\x6e\x73"); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("\145\144\151\x74\55\x61\x72\x74\151\x63\154\145\163")); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("\x65\144\151\164\x2d\156\145\167\163")); $this->assertQueryCount(0); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("\x65\144\151\x74\x2d\x61\x72\164\x69\x63\154\145\163")); $this->assertQueryCount(0); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("\105\144\x69\x74\x20\116\x65\167\163")); $this->assertQueryCount(0); } public function the_cache_should_differentiate_by_guard_name() { $this->expectException(PermissionDoesNotExist::class); $this->testUserRole->givePermissionTo(array("\x65\x64\151\x74\x2d\141\x72\164\151\143\154\x65\x73", "\x77\145\x62")); $this->testUser->assignRole("\164\x65\163\x74\x52\157\x6c\145"); $this->testUser->loadMissing("\162\x6f\154\145\163", "\160\x65\x72\x6d\x69\x73\163\151\x6f\156\x73"); $this->resetQueryCount(); $this->assertTrue($this->testUser->hasPermissionTo("\145\x64\151\164\55\x61\162\x74\151\143\154\145\x73", "\167\x65\142")); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); $this->resetQueryCount(); $this->assertFalse($this->testUser->hasPermissionTo("\145\144\x69\x74\55\x61\162\x74\151\x63\154\x65\163", "\x61\x64\x6d\x69\156")); $this->assertQueryCount(1); } public function get_all_permissions_should_use_the_cache() { $this->testUserRole->givePermissionTo($expected = array("\x65\144\x69\164\55\x61\162\164\x69\x63\154\145\x73", "\x65\x64\x69\164\x2d\x6e\145\x77\163")); $this->testUser->assignRole("\x74\x65\163\164\122\x6f\x6c\145"); $this->testUser->loadMissing("\162\x6f\154\145\163\x2e\160\x65\x72\x6d\x69\163\163\x69\x6f\x6e\x73", "\x70\145\x72\155\x69\163\x73\151\x6f\x6e\x73"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); $this->resetQueryCount(); $actual = $this->testUser->getAllPermissions()->pluck("\156\x61\x6d\x65")->sort()->values(); $this->assertEquals($actual, collect($expected)); $this->assertQueryCount(0); } public function get_all_permissions_should_not_over_hydrate_roles() { $this->testUserRole->givePermissionTo(array("\145\144\151\x74\x2d\141\x72\164\151\x63\154\145\163", "\145\x64\x69\164\55\156\145\167\x73")); $permissions = $this->registrar->getPermissions(); $roles = $permissions->flatMap->roles; $this->assertSame($roles[0], $roles[1]); } public function it_can_reset_the_cache_with_artisan_command() { Artisan::call("\160\145\162\155\x69\x73\163\151\157\x6e\72\x63\162\145\x61\x74\145\55\160\145\162\155\151\x73\x73\x69\x6f\x6e", array("\156\141\155\x65" => "\156\145\x77\55\x70\145\162\x6d\x69\163\x73\151\x6f\x6e")); $this->assertCount(1, \Spatie\Permission\Models\Permission::where("\x6e\141\x6d\x65", "\x6e\145\167\x2d\x70\x65\162\155\151\163\x73\x69\157\x6e")->get()); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); Artisan::call("\x70\145\162\155\151\163\163\x69\157\x6e\x3a\x63\141\x63\150\145\x2d\162\x65\x73\145\x74"); $this->resetQueryCount(); $this->registrar->getPermissions(); $this->assertQueryCount($this->cache_init_count + $this->cache_load_count + $this->cache_run_count); } protected function assertQueryCount(int $expected) { $this->assertCount($expected, DB::getQueryLog()); } protected function resetQueryCount() { DB::flushQueryLog(); } }

Function Calls

None

Variables

None

Stats

MD5 4b9b81164c9412364496163a0e534989
Eval Count 0
Decode Time 95 ms