1<?php
2
3/**
4 * Copyright 2015-2017 DataStax, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19namespace Cassandra;
20
21/**
22 * Basic/Simple integration test class to provide common integration test
23 * functionality when a simple setup and teardown is required. This class
24 * should be used for the majority of tests.
25 */
26abstract class BasicIntegrationTest extends \PHPUnit_Framework_TestCase {
27    /**
28     * Conversion value for seconds to milliseconds.
29     */
30    const SECONDS_TO_MILLISECONDS = 1000;
31    /**
32     * Conversion value for seconds to microseconds.
33     */
34    const SECONDS_TO_MICROSECONDS = 1000000;
35
36    /**
37     * Integration test instance (helper class).
38     *
39     * @var Integration
40     */
41    private $integration;
42    /**
43     * Handle for interacting with CCM.
44     *
45     * @var CCM
46     */
47    protected $ccm;
48    /**
49     * Number of nodes in data center one.
50     *
51     * @var int
52     */
53    protected $numberDC1Nodes = 1;
54    /**
55     * Number of nodes in data center two.
56     *
57     * @var int
58     */
59    protected $numberDC2Nodes = 0;
60    /**
61     * Replication factor override.
62     *
63     * @var int
64     */
65    protected $replicationFactor = -1;
66    /**
67     * Established cluster configuration.
68     *
69     * @var \Cassandra\Cluster
70     */
71    protected $cluster;
72    /**
73     * Connected database session.
74     *
75     * @var \Cassandra\Session
76     */
77    protected $session;
78    /**
79     * Version of Cassandra/DSE the session is connected to.
80     *
81     * @var string
82     */
83    protected $serverVersion;
84    /**
85     * Keyspace name being used for the test.
86     *
87     * @var string
88     */
89    protected $keyspaceName;
90    /**
91     * Table name prefix being used for the test.
92     *
93     * @var string
94     */
95    protected $tableNamePrefix;
96    /**
97     * Flag to determine if client authentication should be enabled.
98     *
99     * @var bool
100     */
101    protected $isClientAuthentication = false;
102    /**
103     * Flag to determine if SSL should be enabled.
104     *
105     * @var bool
106     */
107    protected $isSSL = false;
108    /**
109     * Flag to determine if UDA/UDF functionality should be enabled.
110     *
111     * @var bool
112     */
113    protected $isUserDefinedAggregatesFunctions = false;
114
115    /**
116     * Setup the database for the integration tests.
117     */
118    protected function setUp() {
119        // Initialize the database and establish a connection
120        $this->integration = new Integration(get_class(), $this->getName(false),
121            $this->numberDC1Nodes, $this->numberDC2Nodes,
122            $this->replicationFactor, $this->isClientAuthentication,
123            $this->isSSL, $this->isUserDefinedAggregatesFunctions);
124        $this->ccm = $this->integration->ccm;
125        $this->cluster = $this->integration->cluster;
126        $this->session = $this->integration->session;
127        $this->serverVersion = $this->integration->serverVersion;
128
129        // Assign the keyspace and table name for the test
130        $this->keyspaceName = strtolower($this->integration->keyspaceName);
131        $this->tableNamePrefix = strtolower($this->getName(false));
132    }
133
134    /**
135     * Teardown the database for the integration tests.
136     */
137    protected function tearDown() {
138        unset($this->integration);
139        unset($this->ccm);
140        unset($this->session);
141    }
142}
143