S3DataStoreContext::getMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
nc 1
cc 1
eloc 2
nop 0
1
<?php
2
3
namespace AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap;
4
5
use AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait\AwsConfigContextTrait;
6
use AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait\DotEnvContextTrait;
7
use AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait\S3ContextTrait;
8
use AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait\SnsContextTrait;
9
use AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait\SqsContextTrait;
10
use Behat\Behat\Context\Context;
11
use Behat\Behat\Context\SnippetAcceptingContext;
12
use Behat\Behat\Tester\Exception\PendingException;
13
use RandomLib\Factory;
14
15
/**
16
 * Defines application features from the specific context.
17
 */
18
class S3DataStoreContext implements Context, SnippetAcceptingContext
19
{
20
    use AwsConfigContextTrait,
21
        DotEnvContextTrait,
22
        S3ContextTrait,
23
        SqsContextTrait,
24
        SnsContextTrait;
25
    
26
    /** @var  int */
27
    private $largeMessageLength = 512000;
28
    
29
    /** @var  string */
30
    private $largeMessage;
31
    
32
    /** @var  string */
33
    private $message;
34
35
    /**
36
     * @Given /^I have a large message$/
37
     */
38
    public function iHaveLargeMessage()
39
    {
40
        $this->message = gmdate('c') . PHP_EOL . $this->getLargeMessage();
41
    }
42
43
    /**
44
     * @Given /^I have a small message$/
45
     */
46
    public function iHaveASmallMessage()
47
    {
48
        $this->message = gmdate('c') . PHP_EOL . 'Hello, World!';
49
    }
50
51
    /**
52
     * @Given /^I have a small message that contains PHI$/
53
     */
54
    public function iHaveASmallMessageThatContainsPhi()
55
    {
56
        throw new PendingException();
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getLargeMessage()
63
    {
64
        if (!$this->largeMessage) {
65
            $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(__METHOD__);
66
            if (file_exists($filename)) {
67
                // TODO Check file content length.
68
                
69
                return file_get_contents($filename);
70
            }
71
            
72
            $factory = new Factory();
73
            $generator = $factory->getLowStrengthGenerator();
74
            $this->largeMessage = $generator->generateString($this->largeMessageLength);
75
            
76
            file_put_contents($filename, $this->largeMessage);
77
        }
78
        
79
        return $this->largeMessage;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getMessage()
86
    {
87
        return $this->message;
88
    }
89
}
90