Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Apr 6, 2021
1 parent b7b7c09 commit ce576ca
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\ORM\Validation;
namespace SilverStripe\Dev\Validation;

use ReflectionException;
use SilverStripe\Core\ClassInfo;
Expand All @@ -18,8 +18,6 @@
*
* This tool runs automatically via dev/build and outputs notices
* For strict validation it is recommended to hook this up to your unit test suite
*
* @package SilverStripe\ORM\Validation
*/
class RelationValidationService implements Resettable
{
Expand Down
8 changes: 7 additions & 1 deletion src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Core\Resettable;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\Validation\RelationValidationService;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\FormScaffolder;
Expand Down Expand Up @@ -3650,7 +3651,12 @@ public function requireDefaultRecords()
}
}

// Let any extentions make their own database default data
// Validate relations (this needs to be triggered only once)
if (static::class === \Page::class) {
RelationValidationService::singleton()->devBuildCheck();
}

// Let any extensions make their own database default data
$this->extend('requireDefaultRecords', $dummy);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\ORM\Tests\Validation;
namespace SilverStripe\Dev\Tests\Validation;

use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\ORM\Tests\Validation;
namespace SilverStripe\Dev\Tests\Validation;

use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\ORM\Tests\Validation;
namespace SilverStripe\Dev\Tests\Validation;

use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace SilverStripe\ORM\Tests\Validation;
namespace SilverStripe\Dev\Tests\Validation;

use Page;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Validation\RelationValidationService;
use SilverStripe\Dev\Validation\RelationValidationService;

class RelationValidationTest extends SapphireTest
{
Expand Down Expand Up @@ -78,8 +78,8 @@ public function validateCasesProvider(): array
'Hatter' => Member::class,
],
[
'SilverStripe\ORM\Tests\Validation\Member / Hat : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\ORM\Tests\Validation\Hat / Hatter : Relation is not in the expected format (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Member / Hat : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Hat / Hatter : Relation is not in the expected format (needs class.relation format)',
],
],
'ambiguous has_one - incorrect relation name' => [
Expand All @@ -89,8 +89,8 @@ public function validateCasesProvider(): array
'Hatter' => Member::class . '.ObviouslyWrong',
],
[
'SilverStripe\ORM\Tests\Validation\Member / Hat : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\ORM\Tests\Validation\Hat / Hatter : Back relation not found',
'SilverStripe\Dev\Tests\Validation\Member / Hat : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Hat / Hatter : Back relation not found',
],
],
'ambiguous has_one - too many relations' => [
Expand All @@ -101,7 +101,7 @@ public function validateCasesProvider(): array
'HatterCopy' => Member::class . '.Hat',
],
[
'SilverStripe\ORM\Tests\Validation\Member / Hat : Back relation is ambiguous',
'SilverStripe\Dev\Tests\Validation\Member / Hat : Back relation is ambiguous',
],
],
'invalid has one' => [
Expand All @@ -112,7 +112,7 @@ public function validateCasesProvider(): array
'Hat' => Hat::class,
],
[
'SilverStripe\ORM\Tests\Validation\Member / HomeTeam : Relation SilverStripe\ORM\Tests\Validation\Team.UnnecessaryRelation is not in the expected format (needs class only format).'
'SilverStripe\Dev\Tests\Validation\Member / HomeTeam : Relation SilverStripe\Dev\Tests\Validation\Team.UnnecessaryRelation is not in the expected format (needs class only format).'
],
],
'ambiguous has_many - no relation name' => [
Expand All @@ -123,8 +123,8 @@ public function validateCasesProvider(): array
'FreelancerMembers' => Freelancer::class . '.TemporaryTeam',
],
[
'SilverStripe\ORM\Tests\Validation\Team / Members : Relation is not in the expected format (needs class.relation format)',
'SilverStripe\ORM\Tests\Validation\Member / HomeTeam : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Team / Members : Relation is not in the expected format (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Member / HomeTeam : Back relation not found or ambiguous (needs class.relation format)',
],
],
'ambiguous has_many - incorrect relation name' => [
Expand All @@ -135,8 +135,8 @@ public function validateCasesProvider(): array
'FreelancerMembers' => Freelancer::class . '.TemporaryTeam',
],
[
'SilverStripe\ORM\Tests\Validation\Team / Members : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\ORM\Tests\Validation\Member / HomeTeam : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Team / Members : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Member / HomeTeam : Back relation not found or ambiguous (needs class.relation format)',
],
],
'ambiguous has_many - too many relations' => [
Expand All @@ -148,7 +148,7 @@ public function validateCasesProvider(): array
'FreelancerMembers' => Freelancer::class . '.TemporaryTeam',
],
[
'SilverStripe\ORM\Tests\Validation\Member / HomeTeam : Back relation is ambiguous',
'SilverStripe\Dev\Tests\Validation\Member / HomeTeam : Back relation is ambiguous',
],
],
'ambiguous many_many - no relation name' => [
Expand All @@ -158,8 +158,8 @@ public function validateCasesProvider(): array
'TeamHats' => Team::class,
],
[
'SilverStripe\ORM\Tests\Validation\Team / ReserveHats : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\ORM\Tests\Validation\Hat / TeamHats : Relation is not in the expected format (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Team / ReserveHats : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Hat / TeamHats : Relation is not in the expected format (needs class.relation format)',
],
],
'ambiguous many_many - incorrect relation name' => [
Expand All @@ -169,8 +169,8 @@ public function validateCasesProvider(): array
'TeamHats' => Team::class . '.ObviouslyWrong',
],
[
'SilverStripe\ORM\Tests\Validation\Team / ReserveHats : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\ORM\Tests\Validation\Hat / TeamHats : Back relation not found',
'SilverStripe\Dev\Tests\Validation\Team / ReserveHats : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Hat / TeamHats : Back relation not found',
],
],
'ambiguous many_many - too many relations' => [
Expand All @@ -181,7 +181,7 @@ public function validateCasesProvider(): array
'TeamHatsCopy' => Team::class . '.ReserveHats',
],
[
'SilverStripe\ORM\Tests\Validation\Team / ReserveHats : Back relation is ambiguous',
'SilverStripe\Dev\Tests\Validation\Team / ReserveHats : Back relation is ambiguous',
],
],
'ambiguous many_many through - no relation name' => [
Expand All @@ -191,8 +191,8 @@ public function validateCasesProvider(): array
'FreelancerTeams' => Team::class,
],
[
'SilverStripe\ORM\Tests\Validation\Team / Freelancers : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\ORM\Tests\Validation\Member / FreelancerTeams : Relation is not in the expected format (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Team / Freelancers : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Member / FreelancerTeams : Relation is not in the expected format (needs class.relation format)',
],
],
'ambiguous many_many through - incorrect relation name' => [
Expand All @@ -202,8 +202,8 @@ public function validateCasesProvider(): array
'FreelancerTeams' => Team::class . '.ObviouslyWrong',
],
[
'SilverStripe\ORM\Tests\Validation\Team / Freelancers : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\ORM\Tests\Validation\Member / FreelancerTeams : Back relation not found',
'SilverStripe\Dev\Tests\Validation\Team / Freelancers : Back relation not found or ambiguous (needs class.relation format)',
'SilverStripe\Dev\Tests\Validation\Member / FreelancerTeams : Back relation not found',
],
],
'ambiguous many_many through - too many relations' => [
Expand All @@ -214,7 +214,7 @@ public function validateCasesProvider(): array
'FreelancerTeamsCopy' => Team::class . '.Freelancers',
],
[
'SilverStripe\ORM\Tests\Validation\Team / Freelancers : Back relation is ambiguous',
'SilverStripe\Dev\Tests\Validation\Team / Freelancers : Back relation is ambiguous',
],
],
];
Expand Down Expand Up @@ -245,15 +245,15 @@ public function ignoredClassesProvider(): array
Team::class,
'Members',
[
'allow_rules' => ['app' => 'SilverStripe\ORM\Tests\Validation'],
'allow_rules' => ['app' => 'SilverStripe\Dev\Tests\Validation'],
],
false,
],
'class included via allow rules but overwritten by deny rules' => [
Team::class,
null,
[
'allow_rules' => ['app' => 'SilverStripe\ORM\Tests\Validation'],
'allow_rules' => ['app' => 'SilverStripe\Dev\Tests\Validation'],
'deny_rules' => [Team::class],
],
true,
Expand All @@ -262,7 +262,7 @@ public function ignoredClassesProvider(): array
Team::class,
'Members',
[
'allow_rules' => ['app' => 'SilverStripe\ORM\Tests\Validation'],
'allow_rules' => ['app' => 'SilverStripe\Dev\Tests\Validation'],
'deny_rules' => [Team::class],
],
true,
Expand All @@ -271,7 +271,7 @@ public function ignoredClassesProvider(): array
Team::class,
'Members',
[
'allow_rules' => ['app' => 'SilverStripe\ORM\Tests\Validation'],
'allow_rules' => ['app' => 'SilverStripe\Dev\Tests\Validation'],
'deny_relations' => [Team::class . '.Members'],
],
true,
Expand All @@ -280,7 +280,7 @@ public function ignoredClassesProvider(): array
Member::class,
'HomeTeam',
[
'allow_rules' => ['app' => 'SilverStripe\ORM\Tests\Validation'],
'allow_rules' => ['app' => 'SilverStripe\Dev\Tests\Validation'],
'deny_rules' => [Team::class],
'deny_relations' => [Team::class . '.Members'],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\ORM\Tests\Validation;
namespace SilverStripe\Dev\Tests\Validation;

use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
Expand Down

0 comments on commit ce576ca

Please sign in to comment.