<commit_before><?php
/*
Copyright 2002-2012 MarkLogic Corporation.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace MarkLogic\MLPHP\Test;

use MarkLogic\MLPHP;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

/**
 * @package MLPHP\Test
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
abstract class TestBase extends \PHPUnit_Framework_TestCase
{
    protected static $logger;
    private static $api;
    protected static $client;
    protected static $manageClient;
    private static $config = array(
        'host' => '127.0.0.1',
        'port' => 8234,
        'db' => 'mlphp-test',
        'username' => 'admin',
        'password' => '<PASSWORD>',
        'apiName' => 'test-mlphp-rest-api'
    );

    // Runs before each test class
    // https://phpunit.de/manual/current/en/fixtures.html#fixtures.variations
    public static function setUpBeforeClass()
    {
        // Create a logger for tests
        self::$logger = new Logger('test');
        self::$logger->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG));

        // Create a REST API for tests
        self::$api = new MLPHP\RESTAPI(
            self::$config['apiName'],
            self::$config['host'],
            self::$config['db'],
            self::$config['port'],
            self::$config['username'],
            self::$config['password'],
            self::$logger
        );
        if (!self::$api->exists()) {
            self::$api->create();
        } else {
            self::$logger->debug(
              'REST API ' . self::$config['apiName'] . ' already exists'
            );
        }

        // Create a REST client for tests
        self::$client = new MLPHP\RESTClient(
            self::$config['host'],
            self::$config['port'],
            '',
            'v1',
            self::$config['username'],
            self::$config['password'],
            'digest',
            self::$logger
        );

        // Create a manage client for tests
        self::$manageClient = new MLPHP\RESTClient(
            self::$config['host'],
            8002,
            'manage',
            'v2',
            self::$config['username'],
            self::$config['password'],
            'digest',
            self::$logger
        );

        // Clear the REST API database
        $db = new MLPHP\Database(self::$config['db'], self::$manageClient);
        $db->clear();

    }

    // Runs after each test class
    // https://phpunit.de/manual/current/en/fixtures.html#fixtures.variations
    public static function tearDownAfterClass()
    {
        self::$api->delete();
    }

}
<commit_msg>Add database delete() step to teardown in TestBase class<commit_after><?php
/*
Copyright 2002-2012 MarkLogic Corporation.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
namespace MarkLogic\MLPHP\Test;

use MarkLogic\MLPHP;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

/**
 * @package MLPHP\Test
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
abstract class TestBase extends \PHPUnit_Framework_TestCase
{
    protected static $logger;
    private static $api;
    protected static $client;
    protected static $manageClient;
    private static $config = array(
        'host' => '127.0.0.1',
        'port' => 8234,
        'db' => 'mlphp-test',
        'username' => 'admin',
        'password' => '<PASSWORD>',
        'apiName' => 'test-mlphp-rest-api'
    );

    // Runs before each test class
    // https://phpunit.de/manual/current/en/fixtures.html#fixtures.variations
    public static function setUpBeforeClass()
    {
        // Create a logger for tests
        self::$logger = new Logger('test');
        self::$logger->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG));

        // Create a REST API for tests
        self::$api = new MLPHP\RESTAPI(
            self::$config['apiName'],
            self::$config['host'],
            self::$config['db'],
            self::$config['port'],
            self::$config['username'],
            self::$config['password'],
            self::$logger
        );
        if (!self::$api->exists()) {
            self::$api->create();
        } else {
            self::$logger->debug(
              'REST API ' . self::$config['apiName'] . ' already exists'
            );
        }

        // Create a REST client for tests
        self::$client = new MLPHP\RESTClient(
            self::$config['host'],
            self::$config['port'],
            '',
            'v1',
            self::$config['username'],
            self::$config['password'],
            'digest',
            self::$logger
        );

        // Create a manage client for tests
        self::$manageClient = new MLPHP\RESTClient(
            self::$config['host'],
            8002,
            'manage',
            'v2',
            self::$config['username'],
            self::$config['password'],
            'digest',
            self::$logger
        );

        // Clear the REST API database
        $db = new MLPHP\Database(self::$config['db'], self::$manageClient);
        $db->clear();

    }

    // Runs after each test class
    // https://phpunit.de/manual/current/en/fixtures.html#fixtures.variations
    public static function tearDownAfterClass()
    {
        self::$api->delete();
        $db = new MLPHP\Database(self::$config['db'], self::$manageClient);
        $db->delete();
    }

}

{'fraction_non_alphanumeric': 0.14034815045073049, 'fraction_numerical': 0.008703761268262356, 'mean_word_length': 2.2223335002503757, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 42, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3616754', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1771, 'n_words': 485}