<commit_before><?php

namespace Ihsw\Toxiproxy\Test;

use Ihsw\Toxiproxy\Exception\ToxicExistsException;
use Ihsw\Toxiproxy\Exception\NotFoundException;
use Ihsw\Toxiproxy\ToxicTypes;
use Ihsw\Toxiproxy\StreamDirections;

class ProxyTest extends AbstractTest
{
    public function testCreate()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);

        $attr = [
            "latency" => 1000,
            "jitter" => 50
        ];
        $toxic = $proxy->create(ToxicTypes::LATENCY, StreamDirections::UPSTREAM, 1.0, $attr);
        $this->assertEquals(ToxicTypes::LATENCY, $toxic->getType());
        $this->assertEquals(StreamDirections::UPSTREAM, $toxic->getStream());
        $this->assertEquals(1.0, $toxic->getToxicity());
        $this->assertEquals($attr, $toxic->getAttributes());

        $toxiproxy->delete($proxy);
    }

    public function testCreateDuplicate()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $this->createToxic($proxy);
        try {
            $this->createToxic($proxy);
        } catch (\Exception $e) {
            $this->assertInstanceOf(ToxicExistsException::class, $e);
            $this->removeProxy($toxiproxy, $proxy);

            return;
        }

        $this->assertTrue(false);
    }

    public function testGetAll()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);

        $toxics = $proxy->getAll();
        $this->assertEquals($toxic, $toxics[0]);

        $toxiproxy->delete($proxy);
    }

    public function testGet()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);

        $this->assertEquals($toxic, $proxy->get($toxic->getName()));

        $toxiproxy->delete($proxy);
    }

    public function testGetNotFound()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);

        $toxic = $proxy->get("non-existent");
        $this->assertNull($toxic);

        $toxiproxy->delete($proxy);
    }

    public function testUpdate()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);

        $toxic->setToxicity(0.5);
        $updatedToxic = $proxy->update($toxic);
        $this->assertEquals($updatedToxic->getToxicity(), $toxic->getToxicity());

        $toxiproxy->delete($proxy);
    }

    public function testDelete()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);
        $proxy->delete($toxic);
        $toxiproxy->delete($proxy);
        $this->assertTrue(true);
    }

    public function testDeleteNotFound()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);
        $proxy->delete($toxic);


        try {
            $proxy->delete($toxic);
        } catch (\Exception $e) {
            $this->assertInstanceOf(NotFoundException::class, $e);
            $toxiproxy->delete($proxy);

            return;
        }

        $this->assertTrue(false);
    }
}<commit_msg>Add test for update-not-found failure mode.<commit_after><?php

namespace Ihsw\Toxiproxy\Test;

use Ihsw\Toxiproxy\Exception\ToxicExistsException;
use Ihsw\Toxiproxy\Exception\NotFoundException;
use Ihsw\Toxiproxy\ToxicTypes;
use Ihsw\Toxiproxy\StreamDirections;

class ProxyTest extends AbstractTest
{
    public function testCreate()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);

        $attr = [
            "latency" => 1000,
            "jitter" => 50
        ];
        $toxic = $proxy->create(ToxicTypes::LATENCY, StreamDirections::UPSTREAM, 1.0, $attr);
        $this->assertEquals(ToxicTypes::LATENCY, $toxic->getType());
        $this->assertEquals(StreamDirections::UPSTREAM, $toxic->getStream());
        $this->assertEquals(1.0, $toxic->getToxicity());
        $this->assertEquals($attr, $toxic->getAttributes());

        $toxiproxy->delete($proxy);
    }

    public function testCreateDuplicate()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $this->createToxic($proxy);
        try {
            $this->createToxic($proxy);
        } catch (\Exception $e) {
            $this->assertInstanceOf(ToxicExistsException::class, $e);
            $this->removeProxy($toxiproxy, $proxy);

            return;
        }

        $this->assertTrue(false);
    }

    public function testGetAll()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);

        $toxics = $proxy->getAll();
        $this->assertEquals($toxic, $toxics[0]);

        $toxiproxy->delete($proxy);
    }

    public function testGet()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);

        $this->assertEquals($toxic, $proxy->get($toxic->getName()));

        $toxiproxy->delete($proxy);
    }

    public function testGetNotFound()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);

        $toxic = $proxy->get("non-existent");
        $this->assertNull($toxic);

        $toxiproxy->delete($proxy);
    }

    public function testUpdate()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);

        $toxic->setToxicity(0.5);
        $updatedToxic = $proxy->update($toxic);
        $this->assertEquals($updatedToxic->getToxicity(), $toxic->getToxicity());

        $toxiproxy->delete($proxy);
    }

    public function testUpdateNotFound()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);
        $proxy->delete($toxic);

        try {
            $proxy->update($toxic);
        } catch (\Exception $e) {
            $this->assertInstanceOf(NotFoundException::class, $e);
            $toxiproxy->delete($proxy);

            return;
        }

        $this->assertTrue(false);
    }

    public function testDelete()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);
        $proxy->delete($toxic);
        $toxiproxy->delete($proxy);
        $this->assertTrue(true);
    }

    public function testDeleteNotFound()
    {
        $toxiproxy = $this->createToxiproxy();
        $proxy = $this->createProxy($toxiproxy);
        $toxic = $this->createToxic($proxy);
        $proxy->delete($toxic);

        try {
            $proxy->delete($toxic);
        } catch (\Exception $e) {
            $this->assertInstanceOf(NotFoundException::class, $e);
            $toxiproxy->delete($proxy);

            return;
        }

        $this->assertTrue(false);
    }
}
{'fraction_non_alphanumeric': 0.164017539051795, 'fraction_numerical': 0.00356261989586188, 'mean_word_length': 2.5158959537572256, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 135, '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': '2599564', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2212, 'n_words': 313}