Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
meritoo committed Oct 19, 2019
1 parent 04c93f6 commit 042e59d
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 49 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Meritoo Common Bundle
e# Meritoo Common Bundle

Common & useful classes, resources, extensions. Based on Symfony framework.

# 0.1.28

1. Implement [phpspec](http://www.phpspec.net)

# 0.1.27

1. PHP CS Fixer > configuration > make more readable & remove unnecessary code
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"doctrine/annotations": "^1.6",
"meritoo/common-library": "^1.0.0",
"meritoo/common-library": "^1.0",
"symfony/framework-bundle": "^3.4|^4.1",
"symfony/validator": "^4.1",
"twig/extensions": "^1.5"
Expand All @@ -21,6 +21,7 @@
"friendsofphp/php-cs-fixer": "^2.15",
"infection/infection": "^0.13.1",
"php-coveralls/php-coveralls": "^2.1",
"phpspec/phpspec": "^5.1",
"phpstan/phpstan": "^0.11.8",
"phpunit/phpunit": "^8.1",
"sebastian/phpcpd": "^4.1",
Expand Down
4 changes: 4 additions & 0 deletions phpspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
suites:
main_suite:
namespace: Meritoo\CommonBundle
verbose: true
54 changes: 54 additions & 0 deletions spec/Meritoo/CommonBundle/Application/DescriptorSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Meritoo\CommonBundle\Application;

use Meritoo\Common\ValueObject\Version;
use Meritoo\CommonBundle\Application\Descriptor;
use PhpSpec\ObjectBehavior;

class DescriptorSpec extends ObjectBehavior
{
public function it_is_initializable(): void
{
$this->shouldHaveType(Descriptor::class);
}

public function it_has_name(): void
{
$this->getName()->shouldReturn('test of name');
}

public function it_has_description(): void
{
$this->getDescription()->shouldReturn('test of description');
}

public function it_has_version(): void
{
$this->getVersion()->shouldBeLike(new Version(1, 0, 1));
}

public function it_is_convertible_to_string(): void
{
$this->__toString()->shouldReturn('test of name | test of description | 1.0.1');
}

public function it_is_convertible_to_string_without_version(): void
{
$this->beConstructedWith('test of name', 'test of description', null);
$this->__toString()->shouldReturn('test of name | test of description | -');
}

public function let(): void
{
$this->beConstructedWith('test of name', 'test of description', new Version(1, 0, 1));
}
}
165 changes: 165 additions & 0 deletions spec/Meritoo/CommonBundle/Bundle/DescriptorSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Meritoo\CommonBundle\Bundle;

use Meritoo\Common\Collection\StringCollection;
use Meritoo\CommonBundle\Bundle\Descriptor;
use PhpSpec\ObjectBehavior;

class DescriptorSpec extends ObjectBehavior
{
public function it_is_initializable(): void
{
$this->shouldHaveType(Descriptor::class);
}

public function it_has_name(): void
{
$this->getName()->shouldReturn('');
$value = 'Test';

$this->setName($value);
$this->getName()->shouldReturn($value);
}

public function it_has_short_name(): void
{
$this->getShortName()->shouldReturn('');
}

public function it_has_configuration_root_name(): void
{
$this->getConfigurationRootName()->shouldReturn('');
$value = 'TestConfiguration';

$this->setConfigurationRootName($value);
$this->getConfigurationRootName()->shouldReturn($value);
}

public function it_has_root_namespace(): void
{
$this->getRootNamespace()->shouldReturn('');
$value = 'My\\TestBundle';

$this->setRootNamespace($value);
$this->getRootNamespace()->shouldReturn($value);
}

public function it_has_path(): void
{
$this->getPath()->shouldReturn('');
$value = '/my/test-bundle';

$this->setPath($value);
$this->getPath()->shouldReturn($value);
}

public function it_has_parent_bundle_descriptor(): void
{
$this->getParentBundleDescriptor()->shouldReturn(null);
$value = new Descriptor('ParentBundle', 'ThisIsParent');

$this->setParentBundleDescriptor($value);
$this->getParentBundleDescriptor()->shouldReturn($value);
}

public function it_has_child_bundle_descriptor(): void
{
$this->getChildBundleDescriptor()->shouldReturn(null);
$value = new Descriptor('ChildBundle', 'ThisIsChild');

$this->setChildBundleDescriptor($value);
$this->getChildBundleDescriptor()->shouldReturn($value);
}

public function it_has_data_fixtures(): void
{
$this->getDataFixtures()->shouldBeLike(new StringCollection());

$value = [
'Data/Fixture1',
'Data/Fixture2',
];

$this->addDataFixtures($value);
$this->getDataFixtures()->shouldBeLike(new StringCollection($value));
}

public function it_has_data_fixtures_directory_path(): void
{
$this->getDataFixturesDirectoryPath()->shouldBeNull();
$value = '/my/test-bundle';

$this->setPath($value);
$this->getDataFixturesDirectoryPath()->shouldReturn($value . '/' . Descriptor::PATH_DATA_FIXTURES);
}

public function it_has_file(): void
{
$this->hasFile('')->shouldReturn(false);

$path = '/my/test-bundle';
$this->setPath($path);
$this->hasFile('test/test')->shouldReturn(false);

$path = '/my/test-bundle';
$this->setPath($path);
$this->hasFile('/my/test-bundle/configuration/routing/authorized.yaml')->shouldReturn(true);
}

public function it_is_convertible_to_array(): void
{
$this->toArray()->shouldReturn([
'name' => '',
'shortName' => '',
'configurationRootName' => '',
'rootNamespace' => '',
'path' => '',
'dataFixtures' => [],
])
;

$name = 'Test';
$configurationRootName = 'TestConfiguration';
$rootNamespace = 'My\\TestBundle';
$path = '/my/test-bundle';
$fixturesPaths = [
'Data/Fixture1',
'Data/Fixture2',
];

$this->setName($name);
$this->setConfigurationRootName($configurationRootName);
$this->setRootNamespace($rootNamespace);
$this->setPath($path);
$this->addDataFixtures($fixturesPaths);

$this->toArray()->shouldReturn([
'name' => $name,
'shortName' => 'test',
'configurationRootName' => $configurationRootName,
'rootNamespace' => $rootNamespace,
'path' => $path,
'dataFixtures' => $fixturesPaths,
])
;
}

public function it_may_be_created_from_array(): void
{
//todo
}

public function it_may_be_created_from_bundle(): void
{
//todo
}
}
49 changes: 49 additions & 0 deletions spec/Meritoo/CommonBundle/Bundle/DescriptorsSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Meritoo\CommonBundle\Bundle;

use Meritoo\Common\Collection\StringCollection;
use Meritoo\CommonBundle\Bundle\Descriptor;
use Meritoo\CommonBundle\Bundle\Descriptors;
use PhpSpec\ObjectBehavior;

class DescriptorsSpec extends ObjectBehavior
{
public function it_is_initializable(): void
{
$this->shouldHaveType(Descriptors::class);
}

public function is_a_collection(): void
{
$this->shouldBeAnInstanceOf(StringCollection::class);
}

public function it_has_not_descriptor(): void
{
$this->beConstructedWith([new Descriptor()]);
$this->getDescriptor('Test\Namespace\ClassName')->shouldBeNull();
}

public function it_has_descriptor(): void
{
$descriptor = new Descriptor('Test', '', 'Test\Namespace');

$this->beConstructedWith([
$descriptor,
]);

$this
->getDescriptor('Test\Namespace\ClassName')
->shouldBeLike($descriptor)
;
}
}
10 changes: 5 additions & 5 deletions src/Bundle/Descriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Meritoo\CommonBundle\Bundle;

use Meritoo\Common\Collection\Collection;
use Meritoo\Common\Collection\StringCollection;
use Meritoo\Common\Utilities\Miscellaneous;
use Meritoo\Common\Utilities\Regex;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand Down Expand Up @@ -82,7 +82,7 @@ class Descriptor
/**
* Names of files with data fixtures from bundle
*
* @var Collection
* @var StringCollection
*/
private $dataFixtures;

Expand Down Expand Up @@ -112,7 +112,7 @@ public function __construct(
$this->childBundleDescriptor = $childBundleDescriptor;

$this->shortName = '';
$this->dataFixtures = new Collection();
$this->dataFixtures = new StringCollection();
}

/**
Expand Down Expand Up @@ -256,9 +256,9 @@ public function setChildBundleDescriptor(?Descriptor $childBundleDescriptor): De
/**
* Returns names of files with data fixtures from bundle
*
* @return Collection
* @return StringCollection
*/
public function getDataFixtures(): Collection
public function getDataFixtures(): StringCollection
{
return $this->dataFixtures;
}
Expand Down

0 comments on commit 042e59d

Please sign in to comment.