Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_dbal_sql_affected_rows_test
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 setUp
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_update
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 test_update_all_matched_unequal_updated
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 test_update_same_value_matched_unequal_updated
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 test_insert
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_dbal_sql_affected_rows_test extends phpbb_database_test_case
15{
16    /** @var \phpbb\db\driver\driver_interface */
17    protected $db;
18
19    protected function setUp(): void
20    {
21        parent::setUp();
22        $this->db = $this->new_dbal();
23    }
24
25    public function getDataSet()
26    {
27        return $this->createXMLDataSet(__DIR__ . '/fixtures/config.xml');
28    }
29
30    public function test_update()
31    {
32        $sql = 'UPDATE ' . CONFIG_TABLE . "
33            SET config_value = 'bertie'";
34        $this->db->sql_query($sql);
35
36        $this->assertEquals(2, $this->db->sql_affectedrows());
37    }
38
39    public function test_update_all_matched_unequal_updated()
40    {
41        $sql = 'UPDATE ' . CONFIG_TABLE . "
42            SET config_value = 'foo'";
43        $this->db->sql_query($sql);
44
45        $this->assertEquals(2, $this->db->sql_affectedrows());
46    }
47
48    public function test_update_same_value_matched_unequal_updated()
49    {
50        $sql = 'UPDATE ' . CONFIG_TABLE . "
51            SET config_value = 'foo'
52            WHERE config_value = 'foo'";
53        $this->db->sql_query($sql);
54
55        $this->assertEquals(1, $this->db->sql_affectedrows());
56    }
57
58    public function test_insert()
59    {
60        $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
61            'config_name'    => 'bertie',
62            'config_value'    => 'rules',
63        ));
64        $this->db->sql_query($sql);
65
66        $this->assertEquals(1, $this->db->sql_affectedrows());
67    }
68}