<commit_before><?php

namespace SpeckCatalogTest\Service;

use PHPUnit\Extensions\Database\TestCase;

class ProductTest extends \PHPUnit_Framework_TestCase
{
    public function testFoo(){}
}<commit_msg>start on product service unit tests<commit_after><?php

namespace SpeckCatalogTest\Service;

use PHPUnit\Extensions\Database\TestCase;

class ProductTest extends \PHPUnit_Framework_TestCase
{
    public function testUpdateGetsValuesFromDataForOriginalValsFromArray()
    {
        $data = array('product_id' => 1);
        $mockMapper = $this->getMock('\SpeckCatalog\Mapper\AbstractMapper');
        $mockMapper->expects($this->once())
            ->method('update')
            ->with($data, $data);
        $service = $this->getService();
        $service->setEntityMapper($mockMapper);
        $service->update($data, null);
    }

    public function testUpdateGetsValuesFromDataForOriginalValsFromProduct()
    {
        $data = array('product_id' => 97);
        $product = new \SpeckCatalog\Model\Product();
        $product->setProductId(97);
        $mockMapper = $this->getMock('\SpeckCatalog\Mapper\AbstractMapper');
        $mockMapper->expects($this->once())
            ->method('update')
            ->with($product, $data);
        $service = $this->getService();
        $service->setEntityMapper($mockMapper);
        $service->update($product, null);
    }

    public function getService()
    {
        return new \SpeckCatalog\Service\Product();
    }

    public function testPopulatePopulatesProduct()
    {
        $service = $this->getService();

        $optionService = $this->getMock('\SpeckCatalog\Service\Option');
        $optionService->expects($this->once())
            ->method('getByProductId')
            ->will($this->returnValue(array(new \SpeckCatalog\Model\Option\Relational)));
        $service->setOptionService($optionService);

        $imageService = $this->getMock('\SpeckCatalog\Service\Image');
        $imageService->expects($this->once())
            ->method('getImages')
            ->will($this->returnValue(array(new \SpeckCatalog\Model\ProductImage\Relational)));
        $service->setImageService($imageService);

        $documentService = $this->getMock('\SpeckCatalog\Service\Document');
        $documentService->expects($this->once())
            ->method('getDocuments')
            ->will($this->returnValue(array(new \SpeckCatalog\Model\Document\Relational)));
        $service->setDocumentService($documentService);

        $productUomService = $this->getMock('\SpeckCatalog\Service\ProductUom');
        $productUomService->expects($this->once())
            ->method('getByProductId')
            ->will($this->returnValue(array(new \SpeckCatalog\Model\ProductUom\Relational)));
        $service->setProductUomService($productUomService);

        $specService = $this->getMock('\SpeckCatalog\Service\Spec');
        $specService->expects($this->once())
            ->method('getByProductId')
            ->will($this->returnValue(array(new \SpeckCatalog\Model\Spec\Relational)));
        $service->setSpecService($specService);

        $companyService = $this->getMock('\SpeckCatalog\Service\Company');
        $companyService->expects($this->once())
            ->method('findById')
            ->will($this->returnValue(new \SpeckCatalog\Model\Company\Relational));
        $service->setCompanyService($companyService);

        $product = new \SpeckCatalog\Model\Product\Relational;
        $product->setProductId('111');
        $service->populate($product);

        $options = $product->getOptions();
        $this->assertTrue(is_array($options));
        $this->assertTrue(count($options) === 1);

        $images = $product->getImages();
        $this->assertTrue(is_array($images));
        $this->assertTrue(count($images) === 1);

        $documents = $product->getDocuments();
        $this->assertTrue(is_array($documents));
        $this->assertTrue(count($documents) === 1);

        $uoms = $product->getUoms();
        $this->assertTrue(is_array($uoms));
        $this->assertTrue(count($uoms) === 1);

        $specs = $product->getSpecs();
        $this->assertTrue(is_array($specs));
        $this->assertTrue(count($specs) === 1);

        $manufacturer = $product->getManufacturer();
        $this->assertInstanceOf('\SpeckCatalog\Model\Company', $manufacturer);
    }

}
{'fraction_non_alphanumeric': 0.1629663538567178, 'fraction_numerical': 0.002975509269855802, 'mean_word_length': 3.2059672762271414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 84, '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': '5927706', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1233, 'n_words': 151}