VariationVersionTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace SilverShop\Tests\Model\Variation;
4
5
use SilverShop\Model\Variation\AttributeType;
6
use SilverShop\Model\Variation\Variation;
7
use SilverShop\Page\Product;
8
use SilverStripe\Dev\SapphireTest;
9
10
/**
11
 * Test product variation capabilities.
12
 *
13
 * @link       ProductVariation
14
 * @link       ProductVariationDecorator
15
 * @package    shop
16
 * @subpackage tests
17
 */
18
class VariationVersionTest extends SapphireTest
19
{
20
    public static $fixture_file   = '../../Fixtures/variations.yml';
21
    public static $disable_theme  = true;
22
    protected static $use_draft_site = true;
23
24
    /**
25
     * @var Product
26
     */
27
    protected $mp3player;
28
29
    /**
30
     * @var Product
31
     */
32
    protected $ball;
33
34
    /**
35
     * @var Variation
36
     */
37
    protected $redlarge;
38
39
    public function setUp(): void
40
    {
41
        parent::setUp();
42
        $this->ball = $this->objFromFixture(Product::class, "ball");
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->objFromFixture(Si...Product::class, 'ball') of type SilverStripe\ORM\DataObject is incompatible with the declared type SilverShop\Page\Product of property $ball.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $this->mp3player = $this->objFromFixture(Product::class, "mp3player");
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->objFromFixture(Si...ct::class, 'mp3player') of type SilverStripe\ORM\DataObject is incompatible with the declared type SilverShop\Page\Product of property $mp3player.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
        $this->redlarge = $this->objFromFixture(Variation::class, "redlarge");
45
    }
46
47
    public function testVariationsPersistOnUnpublish()
48
    {
49
        $color = $this->objFromFixture(AttributeType::class, "color");
50
        $values = ['Black', 'Blue'];
51
        $this->mp3player->generateVariationsFromAttributes($color, $values);
52
        $this->mp3player->publishSingle();
53
54
        $this->mp3player->publish('Stage', 'Stage');
55
56
        $variations = $this->mp3player->Variations();
57
        $this->assertEquals($variations->Count(), 2, "two variations created and persist after product unpublished");
58
    }
59
}
60