diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 39ef9cc4a..9357dda8e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: strategy: max-parallel: 6 matrix: - phpVersions: ['8.2', '8.3', '8.4'] + phpVersions: ['8.2', '8.3', '8.4', '8.5'] fail-fast: false name: PHP ${{ matrix.phpVersions }} steps: diff --git a/src/Halcyon/Exception/ModelException.php b/src/Halcyon/Exception/ModelException.php index f1bee9879..8975efd1e 100644 --- a/src/Halcyon/Exception/ModelException.php +++ b/src/Halcyon/Exception/ModelException.php @@ -2,6 +2,8 @@ use October\Rain\Halcyon\Model; use October\Rain\Exception\ValidationException; +use Illuminate\Support\MessageBag; +use Exception; /** * ModelException used when validation fails, contains the invalid model for easy analysis @@ -16,16 +18,41 @@ class ModelException extends ValidationException */ protected $model; + /** + * @var MessageBag validationErrors + */ + protected $validationErrors; + /** * __construct receives the invalid model */ public function __construct(Model $model) { $this->model = $model; - $this->errors = $model->errors(); + $this->validationErrors = $model->errors(); + + // Bypass parent constructor to avoid Validator facade dependency + Exception::__construct($this->validationErrors->first()); + $this->evalErrors(); } + /** + * errors returns validation errors + */ + public function errors(): array + { + return $this->validationErrors->messages(); + } + + /** + * getErrors returns the message bag instance + */ + public function getErrors(): MessageBag + { + return $this->validationErrors; + } + /** * getModel returns the model with invalid attributes */ diff --git a/src/Html/HtmlBuilder.php b/src/Html/HtmlBuilder.php index e83f1bf41..0db1f3125 100644 --- a/src/Html/HtmlBuilder.php +++ b/src/Html/HtmlBuilder.php @@ -444,7 +444,7 @@ public static function limit($html, $maxLength = 100, $end = '...') break; } - if ($tag[0] === '&' || ord($tag) >= 0x80) { + if ($tag[0] === '&' || ord($tag[0]) >= 0x80) { $result .= $tag; $printedLength++; } diff --git a/src/Translation/Translator.php b/src/Translation/Translator.php index cf6be3b46..fd1f3445a 100644 --- a/src/Translation/Translator.php +++ b/src/Translation/Translator.php @@ -45,7 +45,7 @@ public function get($key, array $replace = [], $locale = null, $fallback = true) // Laravel notes that with JSON translations, there is no usage of a fallback language. // The key is the translation. Here we extend the technology to add fallback support. - if ($fallback && $line === null) { + if ($fallback && $line === null && $this->fallback !== null) { $this->load('*', '*', $this->fallback); $line = $this->loaded['*']['*'][$this->fallback][$key] ?? null; } diff --git a/tests/Html/HtmlBuilderTest.php b/tests/Html/HtmlBuilderTest.php index 5d7bb9ef3..e432e545f 100644 --- a/tests/Html/HtmlBuilderTest.php +++ b/tests/Html/HtmlBuilderTest.php @@ -21,15 +21,17 @@ public function testLimit() $result = with(new HtmlBuilder)->limit("
The quick brown fox jumped over the lazy dog
The quick brown fox jumped over the lazy dog
", 50); $this->assertEquals('The quick brown fox jumped over the lazy dog
The qu...
', $result); - $result = with(new HtmlBuilder)->limit(trim(" + $input = str_replace("\r\n", "\n", trim("The quick brown fox jumped over the lazy dog
The quick brown fox jumped over the lazy dog
- "), 60); + ")); + $result = with(new HtmlBuilder)->limit($input, 60); - $this->assertEquals(trim(' + $expected = str_replace("\r\n", "\n", trim('The quick brown fox jumped over the lazy dog
The...
- '), $result); + ')); + $this->assertEquals($expected, $result); } public function testClean() diff --git a/tests/Mail/MailerTest.php b/tests/Mail/MailerTest.php index 387046ccc..28ddd2ab8 100644 --- a/tests/Mail/MailerTest.php +++ b/tests/Mail/MailerTest.php @@ -95,7 +95,6 @@ protected static function callProtectedMethod($object, $name, $params = []) $className = get_class($object); $class = new ReflectionClass($className); $method = $class->getMethod($name); - $method->setAccessible(true); return $method->invokeArgs($object, $params); } diff --git a/tests/Parse/MarkdownTest.php b/tests/Parse/MarkdownTest.php index 83d6c7444..72c325fe9 100644 --- a/tests/Parse/MarkdownTest.php +++ b/tests/Parse/MarkdownTest.php @@ -97,7 +97,7 @@ public function testParseNonHtml() $normal = $parser->parse($text); // Only accepting one node per line - $this->assertEquals($expected, $normal); + $this->assertEquals(str_replace("\r\n", "\n", $expected), $normal); } public function testParseMultilineHtml() @@ -149,6 +149,6 @@ public function testParseMultilineHtml() $normal = $parser->parse($text); - $this->assertEquals($expected, $normal); + $this->assertEquals(str_replace("\r\n", "\n", $expected), $normal); } } diff --git a/tests/Parse/SyntaxFieldParserTest.php b/tests/Parse/SyntaxFieldParserTest.php index 79a7c94e9..4787da571 100644 --- a/tests/Parse/SyntaxFieldParserTest.php +++ b/tests/Parse/SyntaxFieldParserTest.php @@ -322,7 +322,6 @@ protected static function callProtectedMethod($object, $name, $params = []) $className = get_class($object); $class = new ReflectionClass($className); $method = $class->getMethod($name); - $method->setAccessible(true); return $method->invokeArgs($object, $params); } @@ -331,7 +330,6 @@ public static function getProtectedProperty($object, $name) $className = get_class($object); $class = new ReflectionClass($className); $property = $class->getProperty($name); - $property->setAccessible(true); return $property->getValue($object); } @@ -340,7 +338,6 @@ public static function setProtectedProperty($object, $name, $value) $className = get_class($object); $class = new ReflectionClass($className); $property = $class->getProperty($name); - $property->setAccessible(true); return $property->setValue($object, $value); } } diff --git a/tests/Scaffold/ScaffoldBaseTest.php b/tests/Scaffold/ScaffoldBaseTest.php index 62975091d..55de50adb 100644 --- a/tests/Scaffold/ScaffoldBaseTest.php +++ b/tests/Scaffold/ScaffoldBaseTest.php @@ -25,7 +25,6 @@ protected static function callProtectedMethod($object, $name, $params = []) $className = get_class($object); $class = new ReflectionClass($className); $method = $class->getMethod($name); - $method->setAccessible(true); return $method->invokeArgs($object, $params); } @@ -34,7 +33,6 @@ public static function getProtectedProperty($object, $name) $className = get_class($object); $class = new ReflectionClass($className); $property = $class->getProperty($name); - $property->setAccessible(true); return $property->getValue($object); } @@ -43,7 +41,6 @@ public static function setProtectedProperty($object, $name, $value) $className = get_class($object); $class = new ReflectionClass($className); $property = $class->getProperty($name); - $property->setAccessible(true); return $property->setValue($object, $value); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 522796664..724c229b7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,7 +20,6 @@ protected static function callProtectedMethod($object, $name, $params = []) $className = get_class($object); $class = new ReflectionClass($className); $method = $class->getMethod($name); - $method->setAccessible(true); return $method->invokeArgs($object, $params); }