forked from PGBI/cakephp3-soft-delete
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
テスト用のテーブルクラス作成 cakephp/cakephp-codesniffer追加 bootstrap.phpは別のCakePHP4プラグインからコピー
- Loading branch information
1 parent
77e972f
commit ed0f11a
Showing
10 changed files
with
430 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
composer.lock | ||
Vagrantfile | ||
vendor | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="CakePHP_Custom"> | ||
<description>CakePHP coding standard</description> | ||
|
||
<exclude-pattern>\.git</exclude-pattern> | ||
|
||
<rule ref="Zend.NamingConventions"> | ||
<exclude name="Zend.NamingConventions.ValidVariableName" /> | ||
</rule> | ||
|
||
<rule ref="PSR2"/> | ||
|
||
<!-- | ||
Property and method names with underscore prefix are allowed in CakePHP. | ||
Not using underscore prefix is a recommendation of PSR2, not a requirement. | ||
--> | ||
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="PSR2.Methods.MethodDeclaration.Underscore"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="Squiz.NamingConventions.ValidFunctionName.PublicUnderscore"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="PEAR.NamingConventions.ValidFunctionName.PublicUnderscore"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="Zend.NamingConventions.ValidVariableName"> | ||
</rule> | ||
<rule ref="Zend.NamingConventions.ValidVariableName.PrivateNoUnderscore"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="Zend.NamingConventions.ValidVariableName.ContainsNumbers"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="Zend.NamingConventions.ValidVariableName.StringVarContainsNumbers"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="Zend.NamingConventions.ValidVariableName.MemberVarContainsNumbers"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="Zend.NamingConventions.ValidVariableName.NotCamelCaps"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="Zend.NamingConventions.ValidVariableName.MemberVarNotCamelCaps"> | ||
<severity>0</severity> | ||
</rule> | ||
|
||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"> | ||
<properties> | ||
<property name="ignoreBlankLines" value="false"/> | ||
</properties> | ||
</rule> | ||
|
||
<!-- | ||
Temporarily ignore until API docblock formatting and line length issues in core code are fixed. | ||
--> | ||
<rule ref="CakePHP.Commenting.FunctionComment" /> | ||
<rule ref="CakePHP.Commenting.FunctionComment.ParamCommentNotCapital"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="CakePHP.Commenting.FunctionComment.ParamCommentFullStop"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="CakePHP.Commenting.FunctionComment.ThrowsNotCapital"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="CakePHP.Commenting.FunctionComment.ThrowsNoFullStop"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="CakePHP.Commenting.FunctionComment.EmptyThrows"> | ||
<severity>0</severity> | ||
</rule> | ||
<rule ref="Generic.Files.LineLength.TooLong"> | ||
<severity>0</severity> | ||
</rule> | ||
|
||
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/> | ||
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/> | ||
|
||
<rule ref="Squiz.Classes.LowercaseClassKeywords"/> | ||
|
||
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/> | ||
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/> | ||
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/> | ||
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/> | ||
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/> | ||
|
||
<rule ref="Squiz.Commenting.DocCommentAlignment"/> | ||
<rule ref="Generic.Commenting.Todo"/> | ||
|
||
<rule ref="PEAR.ControlStructures.ControlSignature"/> | ||
|
||
<rule ref="Generic.Files.LineEndings"/> | ||
|
||
<rule ref="Generic.Formatting.NoSpaceAfterCast"/> | ||
|
||
<rule ref="Squiz.Operators.ValidLogicalOperators"/> | ||
|
||
<rule ref="Generic.PHP.DeprecatedFunctions"/> | ||
<rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops"/> | ||
<rule ref="Squiz.PHP.Eval"/> | ||
<rule ref="Generic.PHP.ForbiddenFunctions"/> | ||
<rule ref="Squiz.PHP.NonExecutableCode"/> | ||
|
||
<rule ref="Generic.PHP.NoSilencedErrors"/> | ||
|
||
<rule ref="Squiz.Scope.MemberVarScope"/> | ||
<rule ref="Squiz.Scope.StaticThisUsage"/> | ||
|
||
<rule ref="Squiz.WhiteSpace.CastSpacing"/> | ||
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/> | ||
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/> | ||
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/> | ||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/> | ||
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/> | ||
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/> | ||
|
||
<!-- Relax some src/* and tests/* rules --> | ||
<rule ref="PSR1.Files.SideEffects"> | ||
<exclude-pattern>*/config/*</exclude-pattern> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="PSR1.Classes.ClassDeclaration"> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="PSR1.Methods.CamelCapsMethodName"> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="PEAR.NamingConventions.ValidClassName"> | ||
<exclude-pattern>*/CakePHP/*</exclude-pattern> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="Squiz.Classes.ValidClassName"> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="CakePHP.Commenting.FunctionComment"> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="Squiz.NamingConventions.ValidFunctionName"> | ||
<exclude-pattern>*/src/*</exclude-pattern> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="Generic.NamingConventions.CamelCapsFunctionName"> | ||
<exclude-pattern>*/src/*</exclude-pattern> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="PEAR.NamingConventions.ValidFunctionName"> | ||
<exclude-pattern>*/src/*</exclude-pattern> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
|
||
<!-- All rules in ./Sniffs are included automatically --> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace SoftDelete\Test\Table; | ||
|
||
use Cake\ORM\Table; | ||
use Cake\Validation\Validator; | ||
use SoftDelete\Model\Table\SoftDeleteTrait; | ||
|
||
/** | ||
* Posts Model | ||
*/ | ||
class PostsTable extends Table | ||
{ | ||
use SoftDeleteTrait; | ||
|
||
/** | ||
* Initialize method | ||
* | ||
* @param array $config The configuration for the Table. | ||
* @return void | ||
*/ | ||
public function initialize(array $config): void | ||
{ | ||
$this->belongsTo('Users'); | ||
$this->belongsToMany('Tags'); | ||
$this->addBehavior('CounterCache', ['Users' => ['posts_count']]); | ||
} | ||
|
||
/** | ||
* Default validation rules. | ||
* | ||
* @param \Cake\Validation\Validator $validator Validator instance. | ||
* @return \Cake\Validation\Validator | ||
*/ | ||
public function validationDefault(Validator $validator): Validator | ||
{ | ||
$validator | ||
->integer('id') | ||
->allowEmptyString('id', null, 'create'); | ||
$validator | ||
->integer('user_id') | ||
->notEmptyString('user_id'); | ||
|
||
return $validator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace SoftDelete\Test\Table; | ||
|
||
use Cake\ORM\Table; | ||
use Cake\Validation\Validator; | ||
use SoftDelete\Model\Table\SoftDeleteTrait; | ||
|
||
/** | ||
* PostsTags Model | ||
*/ | ||
class PostsTagsTable extends Table | ||
{ | ||
use SoftDeleteTrait; | ||
|
||
/** | ||
* Initialize method | ||
* | ||
* @param array $config The configuration for the Table. | ||
* @return void | ||
*/ | ||
public function initialize(array $config): void | ||
{ | ||
$this->belongsTo('Tags'); | ||
$this->belongsTo('Posts'); | ||
} | ||
|
||
/** | ||
* Default validation rules. | ||
* | ||
* @param \Cake\Validation\Validator $validator Validator instance. | ||
* @return \Cake\Validation\Validator | ||
*/ | ||
public function validationDefault(Validator $validator): Validator | ||
{ | ||
$validator | ||
->integer('id') | ||
->allowEmptyString('id', null, 'create'); | ||
$validator | ||
->integer('post_id') | ||
->notEmptyString('post_id'); | ||
$validator | ||
->integer('tag_id') | ||
->notEmptyString('tag_id'); | ||
|
||
return $validator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace SoftDelete\Test\Table; | ||
|
||
use Cake\ORM\Table; | ||
use Cake\Validation\Validator; | ||
use SoftDelete\Model\Table\SoftDeleteTrait; | ||
|
||
/** | ||
* Tags Model | ||
*/ | ||
class TagsTable extends Table | ||
{ | ||
use SoftDeleteTrait; | ||
|
||
/** | ||
* Soft deletion field | ||
*/ | ||
public $softDeleteField = 'deleted_date'; | ||
|
||
/** | ||
* Initialize method | ||
* | ||
* @param array $config The configuration for the Table. | ||
* @return void | ||
*/ | ||
public function initialize(array $config): void | ||
{ | ||
$this->belongsToMany('Posts', [ | ||
'through' => 'PostsTags', | ||
'joinTable' => 'posts_tags', | ||
'foreignKey' => 'tag_id', | ||
'targetForeignKey' => 'post_id' | ||
]); | ||
$this->hasMany('PostsTags'); | ||
} | ||
|
||
/** | ||
* Default validation rules. | ||
* | ||
* @param \Cake\Validation\Validator $validator Validator instance. | ||
* @return \Cake\Validation\Validator | ||
*/ | ||
public function validationDefault(Validator $validator): Validator | ||
{ | ||
$validator | ||
->integer('id') | ||
->allowEmptyString('id', null, 'create'); | ||
$validator | ||
->requirePresence('name') | ||
->allowEmptyString('name'); | ||
|
||
return $validator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace SoftDelete\Test\Table; | ||
|
||
use Cake\ORM\Table; | ||
use Cake\Validation\Validator; | ||
use SoftDelete\Model\Table\SoftDeleteTrait; | ||
|
||
/** | ||
* Users Model | ||
*/ | ||
class UsersTable extends Table | ||
{ | ||
use SoftDeleteTrait; | ||
|
||
/** | ||
* Initialize method | ||
* | ||
* @param array $config The configuration for the Table. | ||
* @return void | ||
*/ | ||
public function initialize(array $config): void | ||
{ | ||
$this->hasMany('Posts', [ | ||
'dependent' => true, | ||
'cascadeCallbacks' => true, | ||
]); | ||
} | ||
|
||
/** | ||
* Default validation rules. | ||
* | ||
* @param \Cake\Validation\Validator $validator Validator instance. | ||
* @return \Cake\Validation\Validator | ||
*/ | ||
public function validationDefault(Validator $validator): Validator | ||
{ | ||
$validator | ||
->integer('id') | ||
->allowEmptyString('id', null, 'create'); | ||
$validator | ||
->integer('posts_count') | ||
->notEmptyString('posts_count'); | ||
|
||
return $validator; | ||
} | ||
} |
Oops, something went wrong.