1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Behat\Context\Transform; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; |
16
|
|
|
use Webmozart\Assert\Assert; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Mateusz Zalewski <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class TaxonContext implements Context |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var TaxonRepositoryInterface |
25
|
|
|
*/ |
26
|
|
|
private $taxonRepository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param TaxonRepositoryInterface $taxonRepository |
30
|
|
|
*/ |
31
|
|
|
public function __construct(TaxonRepositoryInterface $taxonRepository) |
32
|
|
|
{ |
33
|
|
|
$this->taxonRepository = $taxonRepository; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @Transform /^classified as "([^"]+)"$/ |
38
|
|
|
* @Transform /^belongs to "([^"]+)"$/ |
39
|
|
|
* @Transform /^"([^"]+)" taxon$/ |
40
|
|
|
* @Transform /^"([^"]+)" as a parent taxon$/ |
41
|
|
|
* @Transform /^"([^"]+)" parent taxon$/ |
42
|
|
|
* @Transform /^parent taxon to "([^"]+)"$/ |
43
|
|
|
* @Transform /^taxon with "([^"]+)" name/ |
44
|
|
|
*/ |
45
|
|
|
public function getTaxonByName($name) |
46
|
|
|
{ |
47
|
|
|
$taxon = $this->taxonRepository->findOneByName($name); |
48
|
|
|
Assert::notNull($taxon, sprintf('Taxon with name "%s" does not exist.', $name)); |
49
|
|
|
|
50
|
|
|
return $taxon; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Transform /^taxon with "([^"]+)" code$/ |
55
|
|
|
*/ |
56
|
|
|
public function getTaxonByCode($code) |
57
|
|
|
{ |
58
|
|
|
$taxon = $this->taxonRepository->findOneBy(['code' => $code]); |
59
|
|
|
Assert::notNull($taxon, sprintf('Taxon with code "%s" does not exist.', $code)); |
60
|
|
|
|
61
|
|
|
return $taxon; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @Transform /^classified as "([^"]+)" or "([^"]+)"$/ |
66
|
|
|
*/ |
67
|
|
|
public function getTaxonsByNames($firstTaxon, $secondTaxon) |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
$this->getTaxonByName($firstTaxon), |
71
|
|
|
$this->getTaxonByName($secondTaxon) |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|