Skip to content

Commit

Permalink
Fix tests when atk4/ui is installed and remove atk4/data dev dependen…
Browse files Browse the repository at this point in the history
…cy (#328)
  • Loading branch information
mvorisek authored Oct 4, 2021
1 parent 6cd61da commit 10a3fb5
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 154 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
- open docs/html/index.html in your browser and review documentation changes you have made
- commit your code. Name your commits consistently. See [https://github.com/atk4/core/commits/develop](https://github.com/atk4/core/commits/develop)
- use multiple comments if necessary. I recommend you to use "Github Desktop", where you can even perform partial file commits.
- once commits are done run `git feature publish fix-psr-compatibility`.
- once commits are done run `git feature publish fix-psr-compatibility`.

## Create Pull Request

- Go to [http://github.com/atk4/core](http://github.com/atk4/core) and create Pull Request
Expand All @@ -41,7 +41,7 @@

- Fork atk4/core repository.
- Follow same instructions as above, but use your own repository name
- If you contribute a lot, it would make sense to [set up codeclimate.com for your repo](https://codeclimate.com/github/signup).
- If you contribute a lot, it would make sense to [set up codeclimate.com for your repo](https://codeclimate.com/github/signup).
- You can also enable Travis-CI for your repository easily.

## Verifying your code
Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
}
],
"require": {
"php": ">=7.4.0",
"php": ">=7.4 <8.2",
"ext-json": "*",
"psr/log": "~1.0",
"symfony/polyfill-php80": "^1.17",
"symfony/polyfill-php81": "^1.22",
"symfony/yaml": "^3.4 || ^4.4 || ^5.1"
},
"require-dev": {
"atk4/data": "dev-develop",
"ergebnis/composer-normalize": "^2.13",
"friendsofphp/php-cs-fixer": "^3.0",
"johnkary/phpunit-speedtrap": "^3.3",
Expand All @@ -48,7 +47,6 @@
"symfony/contracts": ">=1.1"
},
"require-dev-release": {
"atk4/data": "~3.1.0",
"ergebnis/composer-normalize": "^2.13",
"friendsofphp/php-cs-fixer": "^3.0",
"johnkary/phpunit-speedtrap": "^3.3",
Expand Down
18 changes: 11 additions & 7 deletions src/AppScopeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ trait AppScopeTrait

protected function assertInstanceOfApp(object $app): void
{
// called from phpunit, allow to use/test this trait without \Atk4\Ui\App class
if (class_exists(\PHPUnit\Framework\TestCase::class, false) && !class_exists(\Atk4\Ui\App::class)) {
return;
}

if (!$app instanceof \Atk4\Ui\App) {
// called from phpunit, allow to use/test this trait without \Atk4\Ui\App class
if (class_exists(\PHPUnit\Framework\TestCase::class, false)) {
foreach (debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
if (str_starts_with($frame['class'] ?? '', 'Atk4\Core\Tests\\')) {
return;
}
}
}

throw new Exception('App must be instance of \Atk4\Ui\App');
}
}
Expand All @@ -76,7 +80,7 @@ protected function assertInstanceOfApp(object $app): void
private function assertNoDirectAppAssignment(): void
{
if ($this->app !== null) {
throw new Exception('App can not be assigned directly');
throw new Exception('App cannot be assigned directly');
}
}

Expand Down Expand Up @@ -109,7 +113,7 @@ public function setApp(object $app)
$this->assertInstanceOfApp($app);
if ($this->issetApp() && $this->getApp() !== $app) {
if ($this->getApp()->catch_exceptions || $this->getApp()->always_run) { // allow to replace App created by AbstractView::initDefaultApp() - TODO fix
throw new Exception('App can not be replaced');
throw new Exception('App cannot be replaced');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function readConfig($files = ['config.php'], string $format = 'php')
$configs = [];
foreach ($files as $file) {
if (!is_readable($file)) {
throw (new Exception('Can not read config file'))
throw (new Exception('Cannot read config file'))
->addMoreInfo('file', $file)
->addMoreInfo('format', $format);
}
Expand Down
6 changes: 3 additions & 3 deletions src/DebugTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public function userMessage(string $message, array $context = [])
public function debugTraceChange(string $trace = 'default'): void
{
$bt = [];
foreach (debug_backtrace() as $line) {
if (isset($line['file'])) {
$bt[] = $line['file'] . ':' . $line['line'];
foreach (debug_backtrace() as $frame) {
if (isset($frame['file'])) {
$bt[] = $frame['file'] . ':' . $frame['line'];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DiContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function setMissingProperty(string $propertyName, $value): void
* Return the argument and assert it is instance of current class.
*
* The best, typehinting-friendly, way to annotate object type if it not defined
* at method header or strong typing in method header can not be used.
* at method header or strong typing in method header cannot be used.
*
* @return static
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function _mergeSeeds(...$seeds)

unset($arguments[0]); // the first argument specifies a class name
if (count($arguments) > 0) {
throw (new Exception('Constructor arguments can not be injected into existing object'))
throw (new Exception('Constructor arguments cannot be injected into existing object'))
->addMoreInfo('object', $obj)
->addMoreInfo('arguments', $arguments);
}
Expand Down
4 changes: 2 additions & 2 deletions src/HookTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private function _rebindHooksIfCloned(): void
// but instead we should throw once the closure this object is cloned
// example of legit use: https://github.com/atk4/audit/blob/eb9810e085a40caedb435044d7318f4d8dd93e11/src/Controller.php#L85
if (get_class($fxThis) === get_class($this->_hookOrigThis) || preg_match('~^Atk4\\\\(?:Core|Dsql|Data)~', get_class($fxThis))) {
throw (new Exception('Object can not be cloned with hook bound to a different object than this'))
throw (new Exception('Object cannot be cloned with hook bound to a different object than this'))
->addMoreInfo('closure_file', $fxRefl->getFileName())
->addMoreInfo('closure_start_line', $fxRefl->getStartLine());
}
Expand Down Expand Up @@ -134,7 +134,7 @@ private function makeHookDynamicFx(\Closure $getFxThisFx, \Closure $fx, array $a
return function ($ignore, &...$args) use ($getFxThisFx, $fx, $isShort) {
$fxThis = $getFxThisFx($this);
if ($fxThis === null) {
throw new Exception('New $this can not be null');
throw new Exception('New $this cannot be null');
}

return \Closure::bind($fx, $fxThis)(...($isShort ? [] : [$this]), ...$args);
Expand Down
2 changes: 1 addition & 1 deletion src/TrackableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trait TrackableTrait
private function assertNoDirectOwnerAssignment(): void
{
if ($this->owner !== null) {
throw new Exception('Owner can not be assigned directly');
throw new Exception('Owner cannot be assigned directly');
}
}

Expand Down
32 changes: 2 additions & 30 deletions src/Translator/Adapter/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Atk4\Core\ConfigTrait;
use Atk4\Core\Translator\ITranslatorAdapter;
use Atk4\Data\Locale;

class Generic implements ITranslatorAdapter
{
Expand Down Expand Up @@ -83,44 +82,19 @@ protected function processMessagePlural($definition, array $parameters = [], int
*/
protected function getDefinition(string $message, string $domain, ?string $locale)
{
$this->loadDefinitionAtk($locale); // need to be called before manual add

return $this->definitions[$locale][$domain][$message] ?? null;
}

protected function loadDefinitionAtk(string $locale): void
{
if (isset($this->definitions[$locale]['atk'])) {
return;
}

$this->definitions[$locale]['atk'] = [];

if (class_exists(\Atk4\Data\Locale::class)) {
$path = Locale::getPath();
$this->addDefinitionFromFile($path . '/' . $locale . '/atk.php', $locale, 'atk', 'php');
}
}

/**
* Load definitions from file.
*/
public function addDefinitionFromFile(string $file, string $locale, string $domain, string $format): void
public function addDefinitionFromArray(array $data, string $locale, string $domain): void
{
$this->loadDefinitionAtk($locale); // need to be called before manual add

$this->readConfig($file, $format);

$this->definitions = array_replace_recursive(
$this->definitions,
[
$locale => [
$domain => $this->config,
$domain => $data,
],
]
);

$this->config = [];
}

/**
Expand All @@ -132,8 +106,6 @@ public function addDefinitionFromFile(string $file, string $locale, string $doma
*/
public function setDefinitionSingle(string $key, $definition, string $locale = 'en', string $domain = 'atk')
{
$this->loadDefinitionAtk($locale); // need to be called before manual add

if (is_string($definition)) {
$definition = [$definition];
}
Expand Down
6 changes: 3 additions & 3 deletions tests/CollectionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testException3(): void
}

/**
* Can not remove non existant object.
* Cannot remove non existant object.
*/
public function testException4(): void
{
Expand All @@ -98,7 +98,7 @@ public function testException4(): void
}

/**
* Can not get non existant object.
* Cannot get non existant object.
*/
public function testException5(): void
{
Expand All @@ -108,7 +108,7 @@ public function testException5(): void
}

/**
* Can not get non existant object.
* Cannot get non existant object.
*/
public function testException6(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public function testFactoryParameters(): void
}

/**
* Object factory can not add not defined properties.
* Object factory cannot add not defined properties.
* Receive as class name.
*/
public function testFactoryParametersException1(): void
Expand All @@ -492,7 +492,7 @@ public function testFactoryParametersException1(): void
}

/**
* Object factory can not add not defined properties.
* Object factory cannot add not defined properties.
* Receive as object.
*/
public function testFactoryParametersException2(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/HookTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function makeCallback(): \Closure
$m->onHook('inc', (clone $m)->makeCallback());
$m = clone $m;
$this->expectException(Exception::class);
$this->expectExceptionMessage('Object can not be cloned with hook bound to a different object than this');
$this->expectExceptionMessage('Object cannot be cloned with hook bound to a different object than this');
$m->hook('inc');
}

Expand Down
65 changes: 0 additions & 65 deletions tests/LocalizationTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Atk4\Core\Tests;
namespace Atk4\Core\Tests\Translator;

use Atk4\Core\AppScopeTrait;
use Atk4\Core\TranslatableTrait;

class TranslatorAdapterAppTest extends TranslatorAdapterBase
class AdapterAppTest extends AdapterBaseTest
{
public function getTranslatableMock(): object
{
Expand Down
Loading

0 comments on commit 10a3fb5

Please sign in to comment.