PdoQueueTest::getUnsupportedItemTypes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
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 Phive\Queue\Tests\Queue\Pdo;
13
14
use Phive\Queue\NoItemAvailableException;
15
use Phive\Queue\Tests\Handler\PdoHandler;
16
use Phive\Queue\Tests\Queue\Concurrency;
17
use Phive\Queue\Tests\Queue\Performance;
18
use Phive\Queue\Tests\Queue\QueueTest;
19
use Phive\Queue\Tests\Queue\Types;
20
use Phive\Queue\Tests\Queue\Util;
21
22
abstract class PdoQueueTest extends QueueTest
23
{
24
    use Concurrency;
25
    use Performance;
26
    use Util;
27
28
    public function getUnsupportedItemTypes()
29
    {
30
        return [Types::TYPE_BINARY_STRING, Types::TYPE_ARRAY, Types::TYPE_OBJECT];
31
    }
32
33
    /**
34
     * @dataProvider provideItemsOfUnsupportedTypes
35
     * @expectedException PHPUnit_Framework_Exception
36
     * @expectedExceptionMessageRegExp /expects parameter 1 to be string|Binary strings are not identical/
37
     */
38
    public function testUnsupportedItemType($item, $type)
39
    {
40
        $this->queue->push($item);
41
42
        if (Types::TYPE_BINARY_STRING === $type && $item !== $this->queue->pop()) {
43
            $this->fail('Binary strings are not identical');
44
        }
45
    }
46
47
    /**
48
     * @dataProvider provideQueueInterfaceMethods
49
     */
50
    public function testThrowExceptionOnMalformedSql($method)
51
    {
52
        $options = self::getHandler()->getOptions();
53
        $options['table_name'] = uniqid('non_existing_table_name_');
54
55
        $handler = new PdoHandler($options);
56
        $queue = $handler->createQueue();
57
58
        try {
59
            $this->callQueueMethod($queue, $method);
60
        } catch (NoItemAvailableException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
61
        } catch (\PDOException $e) {
62
            return;
63
        }
64
65
        $this->fail();
66
    }
67
68
    /**
69
     * @expectedException InvalidArgumentException
70
     * @expectedExceptionMessage PDO driver "foobar" is unsupported
71
     */
72
    public function testThrowExceptionOnUnsupportedDriver()
73
    {
74
        $pdo = new MockPdo();
75
        $pdo->driverName = 'foobar';
76
77
        $handler = self::getHandler();
78
        $class = $handler->getQueueClass();
79
80
        new $class($pdo, $handler->getOption('table_name'));
81
    }
82
}
83