Skip to content

Commit

Permalink
BUG Avoid trying to get singletons fon non-existan classes (#192)
Browse files Browse the repository at this point in the history
BUG Avoid trying to get singletons for non-existant classes
  • Loading branch information
Maxime Rainville authored Apr 28, 2020
1 parent a1d7798 commit 6df2a98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
19 changes: 6 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@ sudo: false
cache:
directories:
- $HOME/.composer/cache/files

php:
- 5.6

env:
matrix:
- PHPUNIT_TEST=1
- PHPCS_TEST=1

matrix:
include:
- php: 5.6
- php: 7.1
env: PHPUNIT_TEST=1
- php: 7.0
env: PHPUNIT_TEST=1
- php: 7.1.2
- php: 7.2
env: PHPUNIT_TEST=1
- php: 7.3
env: PHPUNIT_TEST=1 PHPCS_TEST=1



before_script:
- export PATH=~/.composer/vendor/bin:$PATH
Expand Down
6 changes: 3 additions & 3 deletions src/Context/FixtureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -897,13 +897,13 @@ protected function convertTypeToClass($type)

// Try direct mapping
$class = str_replace(' ', '', ucwords($type));
if (class_exists($class) && is_subclass_of($class, 'SilverStripe\\ORM\\DataObject')) {
if (class_exists($class) && is_subclass_of($class, DataObject::class)) {
return ClassInfo::class_name($class);
}

// Fall back to singular names
foreach (array_values(ClassInfo::subclassesFor('SilverStripe\\ORM\\DataObject')) as $candidate) {
if (strcasecmp(singleton($candidate)->singular_name(), $type) === 0) {
foreach (array_values(ClassInfo::subclassesFor(DataObject::class)) as $candidate) {
if (class_exists($candidate) && strcasecmp(singleton($candidate)->singular_name(), $type) === 0) {
return $candidate;
}
}
Expand Down

0 comments on commit 6df2a98

Please sign in to comment.