Skip to content

Commit

Permalink
Merge pull request #18 from flagbit/3.0
Browse files Browse the repository at this point in the history
Add support for Akeneo 3.0
  • Loading branch information
Antonio Mansilla authored Jun 27, 2019
2 parents b7f6bf3 + a422b78 commit db270ff
Show file tree
Hide file tree
Showing 45 changed files with 618 additions and 258 deletions.
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ cache:
- $HOME/.composer/cache

matrix:
include:
- php: 7.1
- php: 7.2
fast_finish: true
include:
- php: 7.2
- php: 7.3
allow_failures:
- php: 7.3

before_install:
# disable default memory limit
- export INI=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- echo memory_limit = -1 >> $INI
# disable default memory limit
- export INI=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- echo memory_limit = -1 >> $INI

install:
- travis_retry composer install $COMPOSER_OPTS
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG-3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 3.0.0

- Add support for Akeneo 3.0.0.

## BC breaks

- `Flagbit\Bundle\TableAttributeBundle\Normalizer\StructuredAttributeOptionNormalizer` was deleted. `Flagbit\Bundle\TableAttributeBundle\Normalizer\AttributeOptionNormalizer` is now used for its service.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Please note that this project is released with a [Contributor Code of Conduct](C

| Branch | Akeneo Compatibility |
| ------------- |:-------------:|
| `master` | `>= 2.0.5 & < 3.0.0` |
| `master` | `>= 3.0.0` |
| `2.X` | `>= 2.0.5 & < 3.0.0` |
| `2.0` | `>= 2.0.0 & < 2.0.5` |
| `1.X` | `>= 1.6.0 & < 2.0.0` |
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Add `mapping_overrides` in `app/config/config.yml`:
akeneo_storage_utils:
mapping_overrides:
-
original: Pim\Bundle\CatalogBundle\Entity\AttributeOption
original: Akeneo\Pim\Structure\Component\Model\AttributeOption
override: Flagbit\Bundle\TableAttributeBundle\Entity\AttributeOption
```
Expand Down Expand Up @@ -119,8 +119,8 @@ php bin/console --env=prod doctrine:migrations:migrate

This extension supports the latest Akeneo PIM CE/EE stable versions:

* 3.0 (LTS)
* 2.3 (LTS)
* 2.1 and 2.2 (STS)

## Development

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
}
],
"require": {
"akeneo/pim-community-dev": "^2.0.5"
"ext-json": "*",
"akeneo/pim-community-dev": "^3.0.0"
},
"require-dev": {
"phpspec/phpspec": "^4.2",
"phpspec/phpspec": "^5.1",
"phpunit/phpunit": "^7.1",
"squizlabs/php_codesniffer": "*",
"overtrue/phplint": "*",
"leanphp/phpspec-code-coverage": "^4.2"
"overtrue/phplint": "*"
}
}
8 changes: 0 additions & 8 deletions phpspec.yml

This file was deleted.

3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

<logging>
<log type="coverage-clover" target="build/clover.xml"/>
<log type="coverage-html" target="build/coverage-html" title="Flagbit TableAttributeBundle" lowUpperBound="30"
highLowerBound="80" charset="UTF-8" highlight="true" yui="true"/>
<log type="coverage-html" target="build/coverage-html" lowUpperBound="30" highLowerBound="80"/>
<log type="junit" target="build/junit.xml"/>
</logging>
</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace spec\Flagbit\Bundle\TableAttributeBundle\AttributeType;

use Flagbit\Bundle\TableAttributeBundle\AttributeType\TableType;
use PhpSpec\ObjectBehavior;

class TableTypeSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith('text');
}

public function it_is_initializable()
{
$this->shouldHaveType(TableType::class);
}

public function it_returns_flagbit_catalog_table()
{
$this->getName()->shouldReturn('flagbit_catalog_table');
}

public function it_returns_text_forbackend_type()
{
$this->getBackendType()->shouldReturn('text');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace spec\Flagbit\Bundle\TableAttributeBundle\DependencyInjection;

use Flagbit\Bundle\TableAttributeBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use PhpSpec\ObjectBehavior;

class ConfigurationSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType(Configuration::class);
}

public function it_returns_Treebuilder_object()
{
$this->getConfigTreeBuilder()->shouldBeAnInstanceOf(TreeBuilder::Class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace spec\Flagbit\Bundle\TableAttributeBundle\Form;

use Flagbit\Bundle\TableAttributeBundle\Form\TableJsonTransformer;
use PhpSpec\ObjectBehavior;

class TableJsonTransformerSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType(TableJsonTransformer::class);
}

public function it_keeps_transform_value()
{
$originalValue = '{"Blank":{},"NotNull":{}}';
$expectedvalue = '{"Blank":{},"NotNull":{}}';

$this->transform($originalValue)->shouldBe($expectedvalue);
}

public function it_reverse_transforms_to_constraints_array_format()
{
$originalValue = '{"Blank":{},"NotNull":{}}';
$expectedvalue = [
'Blank' => [],
'NotNull' => [],
];

$this->reverseTransform($originalValue)->shouldBe($expectedvalue);
}

public function it_reverse_transform_null()
{
$originalValue = null;

$this->reverseTransform($originalValue)->shouldBeNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Flagbit\Bundle\TableAttributeBundle\Http\Select2JsonResponse;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class Select2JsonResponseSpec extends ObjectBehavior
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace spec\Flagbit\Bundle\TableAttributeBundle\Normalizer;

use Flagbit\Bundle\TableAttributeBundle\Entity\AttributeOption;
use Flagbit\Bundle\TableAttributeBundle\Normalizer\AttributeOptionNormalizer;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class AttributeOptionNormalizerSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType(AttributeOptionNormalizer::class);
}

public function let(NormalizerInterface $baseNormalizer)
{
$this->beConstructedWith($baseNormalizer);
}

public function it_checks_return_type_array_and_right_values
(
AttributeOption $attributeOption,
$baseNormalizer
)
{
$constraints = [
'NotBlank' => [],
'Email' => [],
];

$activatedLocales = [
'onlyActivatedLocales' => true,
];

$baseNormalizer->normalize($attributeOption, 'array', $activatedLocales)->shouldBeCalled();
$attributeOption->getType()->willReturn('text');
$attributeOption->getTypeConfig()->willReturn([]);
$attributeOption->getConstraints()->willReturn($constraints);

$normalizedValues = $this->normalize($attributeOption, 'array', $activatedLocales);

$normalizedValues->shouldBeArray();

$normalizedValues->shouldHaveKey('type');
$normalizedValues->shouldHaveKey('type_config');
$normalizedValues->shouldHaveKey('constraints');

$normalizedValues->shouldHaveKeyWithValue('type', 'text');
$normalizedValues->shouldHaveKeyWithValue('type_config', []);
$normalizedValues->shouldHaveKeyWithValue('constraints', $constraints);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace spec\Flagbit\Bundle\TableAttributeBundle\Provider\Field;

use Flagbit\Bundle\TableAttributeBundle\Provider\Field\TableFieldProvider;
use PhpSpec\ObjectBehavior;
use Akeneo\Pim\Structure\Component\Model\AttributeInterface;


class TableFieldProviderSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType(TableFieldProvider::class);
}

public function it_returns_flagbit_table_field()
{
$element = [
'foo' => 'bar',
];
$this->getField($element)->shouldReturn('flagbit-table-field');
}

public function it_checks_correct_support
(
AttributeInterface $attributeInterface
)
{
$attributeInterface->getType()->willReturn('flagbit_catalog_table');
$this->supports($attributeInterface)->shouldReturn(true);
}

public function it_checks_incorrect_support
(
AttributeInterface $attributeInterface
)
{
$attributeInterface->getType()->willReturn('foo_bar');
$this->supports($attributeInterface)->shouldReturn(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Flagbit\Bundle\TableAttributeBundle\Validator\ConstraintFactory;
use Flagbit\Bundle\TableAttributeBundle\Validator\Constraints\Table;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Form\Exception\ExceptionInterface;
use Symfony\Component\Validator\Constraints as C;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;

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

namespace spec\Flagbit\Bundle\TableAttributeBundle\Validator\ConstraintGuesser;

use Akeneo\Pim\Structure\Component\Model\AttributeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Flagbit\Bundle\TableAttributeBundle\AttributeType\TableType;
use Flagbit\Bundle\TableAttributeBundle\Entity\AttributeOption;
use Flagbit\Bundle\TableAttributeBundle\Validator\ConstraintFactory;
use Flagbit\Bundle\TableAttributeBundle\Validator\ConstraintGuesser\TableGuesser;
use Flagbit\Bundle\TableAttributeBundle\Validator\Constraints\Table;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Validator\Constraint;

class TableGuesserSpec extends ObjectBehavior
{
public function let(ConstraintFactory $constraintFactory)
{
$this->beConstructedWith($constraintFactory);
}

public function it_is_initializable()
{
$this->shouldHaveType(TableGuesser::class);
}

public function it_supports_table_attribute(AttributeInterface $attribute)
{
$attribute->getType()->willReturn(TableType::FLAGBIT_CATALOG_TABLE);
$this->supportAttribute($attribute)->shouldReturn(true);
}

public function it_not_supports_wrong_type(AttributeInterface $attribute)
{
$attribute->getType()->willReturn('not_existing_type');
$this->supportAttribute($attribute)->shouldReturn(false);
}

public function it_creates_constraint_array(
AttributeInterface $attribute,
AttributeOption $attributeOption,
ConstraintFactory $constraintFactory,
Constraint $notBlank,
Constraint $email,
Table $tableConstraint
)
{
$attribute->getOptions()->willReturn(new ArrayCollection([
$attributeOption->getWrappedObject(),
]));
$constraints = [
$notBlank,
$email
];

$attributeOption->getCode()->willReturn('foo');
$constraintFactory->createByConstraintConfig($attributeOption)->willReturn($constraints);

$fieldConstraints['foo'] = $constraints;
$constraintFactory->createTableConstraint($fieldConstraints)->willReturn($tableConstraint);
$this->guessConstraints($attribute)->shouldBeArray();
$this->guessConstraints($attribute)->shouldReturn([$tableConstraint]);
}

public function it_creates_constraint_array_without_options(
AttributeInterface $attribute,
ConstraintFactory $constraintFactory,
Table $tableConstraint
)
{
$attribute->getOptions()->willReturn([]);
$fieldConstraints = [];
$constraintFactory->createTableConstraint($fieldConstraints)->willReturn($tableConstraint);
$this->guessConstraints($attribute)->shouldBeArray();
$this->guessConstraints($attribute)->shouldReturn([$tableConstraint]);
}
}
Loading

0 comments on commit db270ff

Please sign in to comment.