<commit_before><?php

/**
 * This file is part of CoverallsKit.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace coverallskit\spec;

use coverallskit\entity\SourceFile;
use coverallskit\entity\Coverage;

describe('SourceFile', function() {
    before(function() {
        $this->path = realpath(__DIR__ . '/../fixtures/foo.php');
        $this->relativePath = str_replace(getcwd() . '/', '', $this->path);
        $this->sourceFile = new SourceFile($this->path);
    });
    describe('__construct', function() {
        context('when the file does not exist', function() {
            it('should throw coverallskit\exception\FileNotFoundException', function() {
                expect(function() {
                    $source = new SourceFile('bar.php');
                })->toThrow('coverallskit\exception\FileNotFoundException');
            });
        });
    });
    describe('isEmpty', function() {
        context('when the contents of the source file is empty', function() {
            before(function() {
                $this->emptySourcePath = realpath(__DIR__ . '/../fixtures/empty.php');
                $this->emptySourceFile = new SourceFile($this->emptySourcePath);
            });
            it('should return true', function() {
                expect($this->emptySourceFile->isEmpty())->toBeTrue();
            });
        });
    });
    describe('getName', function() {
        it('should return file name', function() {
            expect($this->sourceFile->getName())->toBe($this->path);
        });
    });
    describe('getContent', function() {
        it('should return file content', function() {
            expect($this->sourceFile->getContent())->toBe(trim(file_get_contents($this->path)));
        });
    });
    describe('getCoverages', function() {
        it('should return coverallskit\entity\collection\CoverageCollection instance', function() {
            expect($this->sourceFile->getCoverages())->toBeAnInstanceOf('coverallskit\entity\collection\CoverageCollection');
        });
    });
    describe('addCoverage', function() {
        before(function() {
            $this->coverage = Coverage::unused(1);
            $this->sourceFile->addCoverage($this->coverage);
            $this->retrieveCoverage = $this->sourceFile->getCoverage(1);
        });
        it('should add coverage', function() {
            expect($this->retrieveCoverage)->toEqual($this->coverage);
        });

        context('when line out of range', function() {
            it('should add coverage', function() {
                expect(function() {
                    $coverage = Coverage::unused(999);
                    $this->sourceFile->addCoverage($coverage);
                })->toThrow('coverallskit\exception\LineOutOfRangeException');
            });
        });
    });

    describe('removeCoverage', function() {
        before(function() {
            $this->coverage = Coverage::unused(3);
            $this->sourceFile->addCoverage($this->coverage);
        });
        it('should add coverage', function() {
            $this->sourceFile->removeCoverage($this->coverage);
            expect($this->sourceFile->getCoverage(3))->toBeNull();
        });
    });

    describe('toArray', function() {<commit_msg>add spec<commit_after><?php

/**
 * This file is part of CoverallsKit.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace coverallskit\spec;

use coverallskit\entity\SourceFile;
use coverallskit\entity\Coverage;

describe('SourceFile', function() {
    before(function() {
        $this->path = realpath(__DIR__ . '/../fixtures/foo.php');
        $this->relativePath = str_replace(getcwd() . '/', '', $this->path);
        $this->sourceFile = new SourceFile($this->path);
    });
    describe('__construct', function() {
        context('when the file does not exist', function() {
            it('should throw coverallskit\exception\FileNotFoundException', function() {
                expect(function() {
                    $source = new SourceFile('bar.php');
                })->toThrow('coverallskit\exception\FileNotFoundException');
            });
        });
    });
    describe('isEmpty', function() {
        context('when the contents of the source file is empty', function() {
            before(function() {
                $this->emptySourcePath = realpath(__DIR__ . '/../fixtures/empty.php');
                $this->emptySourceFile = new SourceFile($this->emptySourcePath);
            });
            it('should return true', function() {
                expect($this->emptySourceFile->isEmpty())->toBeTrue();
            });
        });
    });
    describe('getName', function() {
        it('should return file name', function() {
            expect($this->sourceFile->getName())->toBe($this->path);
        });
    });
    describe('getContent', function() {
        it('should return file content', function() {
            expect($this->sourceFile->getContent())->toBe(trim(file_get_contents($this->path)));
        });
    });
    describe('getCoverages', function() {
        it('should return coverallskit\entity\collection\CoverageCollection instance', function() {
            expect($this->sourceFile->getCoverages())->toBeAnInstanceOf('coverallskit\entity\collection\CoverageCollection');
        });
    });
    describe('addCoverage', function() {
        before(function() {
            $this->coverage = Coverage::unused(1);
            $this->sourceFile->addCoverage($this->coverage);
            $this->retrieveCoverage = $this->sourceFile->getCoverage(1);
        });
        it('should add coverage', function() {
            expect($this->retrieveCoverage)->toEqual($this->coverage);
        });

        context('when line out of range', function() {
            it('should add coverage', function() {
                expect(function() {
                    $coverage = Coverage::unused(999);
                    $this->sourceFile->addCoverage($coverage);
                })->toThrow('coverallskit\exception\LineOutOfRangeException');
            });
        });
        context('when the blank line of the last', function() {
            it('should add coverage', function() {
                $coverage = Coverage::unused(4);
                $this->sourceFile->addCoverage($coverage);

                expect($this->sourceFile->getCoverage(4))->toBeNull();
            });
        });
    });

    describe('removeCoverage', function() {
        before(function() {
            $this->coverage = Coverage::unused(3);
            $this->sourceFile->addCoverage($this->coverage);
        });
        it('should add coverage', function() {
            $this->sourceFile->removeCoverage($this->coverage);
            expect($this->sourceFile->getCoverage(3))->toBeNull();
        });
    });

    describe('toArray', function() {
{'fraction_non_alphanumeric': 0.16301564722617354, 'fraction_numerical': 0.002275960170697013, 'mean_word_length': 2.3982600289995166, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 106, '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': '6487514', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1837, 'n_words': 329}