Passed
Push — feature/initial-implementation ( f3915b...fbd338 )
by Fike
02:22
created

AttachmentAware::addDataAttachment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Test\Support\Allure;
6
7
use JMS\Serializer\SerializerBuilder;
8
use Yandex\Allure\Adapter\Support\AttachmentSupport;
9
10
trait AttachmentAware
11
{
12
    use AttachmentSupport;
13
14
    public function addDataAttachment($value, $title = 'data')
15
    {
16
        $tempFile = tempnam(sys_get_temp_dir(), 'ama-team-elasticsearch-');
17
        $serializer = (new SerializerBuilder())->build();
18
        $normalized = $serializer->serialize($value, 'yml');
19
        file_put_contents($tempFile, $normalized);
20
        $this->addAttachment($tempFile, "$title.yml");
21
    }
22
}
23