Completed
Pull Request — master (#3)
by Valentin
11:14
created

SnapshotSourceTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 4
dl 0
loc 26
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testFindByHash() 0 20 1
1
<?php
2
3
namespace Spiral\Tests\Snapshotter\AggregationHandler\Sources;
4
5
use Spiral\Snapshotter\AggregationHandler\Database\Sources\SnapshotSource;
6
use Spiral\Snapshotter\AggregationHandler;
7
use Spiral\Tests\BaseTest;
8
9
class SnapshotSourceTest extends BaseTest
10
{
11
    /**
12
     * Find snapshot record by hash.
13
     */
14
    public function testFindByHash()
15
    {
16
        $snapshot = $this->makeSnapshot('custom error', 777);
17
        $this->handleSnapshot($snapshot, true);
18
19
        $hash = AggregationHandler\Services\SnapshotService::makeHash($snapshot);
20
        $hash2 = 'some second random hash';
21
22
        /** @var SnapshotSource $source */
23
        $source = $this->container->get(SnapshotSource::class);
24
        $this->assertNotEmpty($source->findByHash($hash));
25
        $this->assertEmpty($source->findByHash($hash2));
26
27
        $record = $source->findByHash($hash);
28
        $record->exception_hash = $hash2;
0 ignored issues
show
Bug introduced by
Accessing exception_hash on the interface Spiral\ORM\RecordInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
29
        $record->save();
30
31
        $this->assertEmpty($source->findByHash($hash));
32
        $this->assertNotEmpty($source->findByHash($hash2));
33
    }
34
}