<commit_before><?php

ini_set('error_reporting', E_ALL);;
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

require_once dirname(__DIR__).'/class-array-config-writer.php';


class Array_Config_Writer_Test extends  \PHPUnit\Framework\TestCase {

    /**
     * @var string Path to config file to write 
     */
    public $configFile;

    /**
     * @var Array_Config_Writer 
     */
    public $configWriter;

    public $testDir;

    public function setup()
    {
        $this->testDire = dirname(__DIR__);
        $config_src = __DIR__.'/config-src.php';
        $config = __DIR__.'/config.php';
        $this->configFile = $config;
        file_put_contents($config, file_get_contents($config_src));        
    }

    public function testConstructor()
    {
        $writer = new Array_Config_Writer($this->configFile);
        $this->assertInstanceOf( 'Array_Config_Writer',  $writer);
        $this->assertEmpty($writer->getLastError(), 'Should not have error');
        
        return $writer;
    }


    
   

    /**
     * @depends testConstructor
     */
    public function testWrite($writer)
    {

        $writer->write('siteName', 'Foo');
        $this->assertContains("\$config['siteName'] = 'Foo'", $writer->getContent());
        
        $writer->save();

        $config = require __DIR__.'/config.php';

        $this->assertTrue(is_array($config));
        $this->assertEquals('Foo', $config['siteName']);
        $this->assertFalse($writer->hasError());
    }

      /**
     * @depends testConstructor
     * @covers Array_Config_Writer::write Array_Config_Writer::getContent
     * 
     */
    public function testWriteUpdateInt($writer)
    {
                
        $writer->write('age', 20);
        $this->assertContains("\$config['age'] = 20", $writer->getContent());
        $this->assertContains("\$config['siteName'] = 'Foo'", $writer->getContent(), 'Changes only target');

        $writer->save();

        $config = require __DIR__.'/config.php';

        $this->assertTrue(is_array($config));
        $this->assertEquals(20, $config['age']);
        $this->assertFalse($writer->hasError());

        return $writer;

    }

    /**
     * 
     */
    public function testWriteUpdateStringWithSemiColon($writer)
    {
                
        $writer->write('age', 20);
        $this->assertContains("\$config['age'] = 20", $writer->getContent());
        $this->assertContains("\$config['siteName'] = 'Foo'", $writer->getContent(), 'Changes only target');

        $writer->save();

        $config = require __DIR__.'/config.php';

        $this->assertTrue(is_array($config));
        $this->assertEquals(20, $config['age']);
        $this->assertFalse($writer->hasError());

        return $writer;

    }
    /**
     * @depends testWriteUpdateInt
     */
    public function testWriteUpdateArray($writer)
    {
                
        $currentConfig = require __DIR__.'/config.php';

        $this->assertEquals('New York', $currentConfig['address']['city']);
        $this->assertEquals('USA', $currentConfig['address']['country']);
        
        $newAddress = [
            'line' => 'Line One',
            'city' => 'Lagos',
            'country' => 'Nigeria'
        ];
        $writer->write('address', $newAddress);

        $this->assertContains("\$config['age'] = 20", $writer->getContent());
        $this->assertContains("\$config['siteName'] = 'Foo'", $writer->getContent(), 'Changes only target');
<commit_msg>Remove semi column test<commit_after><?php

ini_set('error_reporting', E_ALL);;
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

require_once dirname(__DIR__).'/class-array-config-writer.php';


class Array_Config_Writer_Test extends  \PHPUnit\Framework\TestCase {

    /**
     * @var string Path to config file to write 
     */
    public $configFile;

    /**
     * @var Array_Config_Writer 
     */
    public $configWriter;

    public $testDir;

    public function setup()
    {
        $this->testDire = dirname(__DIR__);
        $config_src = __DIR__.'/config-src.php';
        $config = __DIR__.'/config.php';
        $this->configFile = $config;
        file_put_contents($config, file_get_contents($config_src));        
    }

    public function testConstructor()
    {
        $writer = new Array_Config_Writer($this->configFile);
        $this->assertInstanceOf( 'Array_Config_Writer',  $writer);
        $this->assertEmpty($writer->getLastError(), 'Should not have error');
        
        return $writer;
    }


    
   

    /**
     * @depends testConstructor
     */
    public function testWrite($writer)
    {

        $writer->write('siteName', 'Foo');
        $this->assertContains("\$config['siteName'] = 'Foo'", $writer->getContent());
        
        $writer->save();

        $config = require __DIR__.'/config.php';

        $this->assertTrue(is_array($config));
        $this->assertEquals('Foo', $config['siteName']);
        $this->assertFalse($writer->hasError());
    }

      /**
     * @depends testConstructor
     * @covers Array_Config_Writer::write Array_Config_Writer::getContent
     * 
     */
    public function testWriteUpdateInt($writer)
    {
                
        $writer->write('age', 20);
        $this->assertContains("\$config['age'] = 20", $writer->getContent());
        $this->assertContains("\$config['siteName'] = 'Foo'", $writer->getContent(), 'Changes only target');

        $writer->save();

        $config = require __DIR__.'/config.php';

        $this->assertTrue(is_array($config));
        $this->assertEquals(20, $config['age']);
        $this->assertFalse($writer->hasError());

        return $writer;

    }

   
    /**
     * @depends testWriteUpdateInt
     */
    public function testWriteUpdateArray($writer)
    {
                
        $currentConfig = require __DIR__.'/config.php';

        $this->assertEquals('New York', $currentConfig['address']['city']);
        $this->assertEquals('USA', $currentConfig['address']['country']);
        
        $newAddress = [
            'line' => 'Line One',
            'city' => 'Lagos',
            'country' => 'Nigeria'
        ];
        $writer->write('address', $newAddress);

        $this->assertContains("\$config['age'] = 20", $writer->getContent());
        $this->assertContains("\$config['siteName'] = 'Foo'", $writer->getContent(), 'Changes only target');

{'fraction_non_alphanumeric': 0.1724727838258165, 'fraction_numerical': 0.004043545878693624, 'mean_word_length': 2.5727777777777776, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '3083876', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1842, 'n_words': 301}