Skip to content

Commit

Permalink
Merge branch 'feature/ETPKIM/1176git_v1' into 'master'
Browse files Browse the repository at this point in the history
Feature/etpkim/1176git v1

See merge request !2
  • Loading branch information
Татьяна Порай committed Mar 17, 2017
2 parents f6f5758 + 8be1574 commit 88b5675
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/.idea/
composer.lock
15 changes: 15 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Composer stores all downloaded packages in the vendor/ directory.
# Do not use the following if the vendor/ directory is commited to
# your git repository.
cache:
paths:
- vendor/

before_script:
# Install composer dependencies
- curl --silent --show-error https://getcomposer.org/installer | php
- php composer.phar install

test:app:
script:
- ./vendor/bin/phpunit --coverage-text
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

before_script:
- travis_retry composer self-update
- travis_retry composer require --no-update satooshi/php-coveralls '~1.0'
- travis_retry composer require --no-update sensiolabs/security-checker:dev-master
- travis_retry composer install

script:
- phpunit --coverage-text --coverage-clover build/logs/clover.xml

after_success:
- travis_retry php vendor/bin/coveralls
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [0.0.0] - 2016-03-24
### Added
+ Initial release to GitHub.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Lite library to work with arrays
[![Build Status](https://travis-ci.org/ptash/сarray.svg?branch=master)](https://travis-ci.org/ptash/сarray)
[![Coverage Status](https://coveralls.io/repos/github/ptash/сarray/badge.svg?branch=master)](https://coveralls.io/github/ptash/сarray?branch=master)
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "cognitive/сarray",
"description": "Library for working with arrays",
"type": "library",
"homepage": "http://www.cognitive.ru/",
"authors": [
{
"name": "Cognitive",
"email": "info@cognitive.ru"
}
],
"require-dev": {
"phpunit/phpunit": "^4"
},
"require": {
"php": ">=5.3"
},
"autoload-dev": {
"psr-4": {
"Cognitive\\CArray\\Test\\": "tests/"
}
},
"autoload": {
"psr-4": {
"Cognitive\\CArray\\": "src/"
}
}
}
19 changes: 19 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Git Fixture Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
30 changes: 30 additions & 0 deletions src/CArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* CArray.php
*/

namespace Cognitive\CArray;

/**
* Class СArray
* @package Cognitive\СArray
*/
class CArray
{
/**
* Checking whether the array is zero-indexed and sequential.
* @param array $arr Input array.
*
* @return bool
*/
public function isAssociative(array $arr)
{
if (array() === $arr) {
return false;
}

$result = array_keys($arr) !== range(0, count($arr) - 1);

return $result;
}
}
95 changes: 95 additions & 0 deletions tests/CArrayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* CArrayTest.php
*/

namespace Cognitive\CArray\Test;

use PHPUnit\Framework\TestCase;
use Cognitive\CArray\CArray;

/**
* Class CArrayTest
* @package Cognitive\Util\Test
*/
class CArrayTest extends TestCase
{
/**
* Data provider for \Cognitive\Util\Test\ArraysTest::testIsAssociative.
*
* @return array
*/
public function providerTestIsAssociative()
{
return [
[
'data' => [
'a' => 'a', 'm' => 'b', 'x' => 'c', 1 => 'hello', 5 => 'z', '7' => 'y', 'hello' => 'x'
],
'result' => true,
],
[
'data' => [
5 => 'z', 1 => 'hello', '7' => 'y', 'a' => 'a', 'hello' => 'x', 'x' => 'c', 'm' => 'b'
],
'result' => true,
],
[
'data' => [
0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 4 => 'e',
],
'result' => false,
],
[
'data' => [
"1" => 'a', "0" => 'b', "2" => 'c'
],
'result' => true,
],
[
'data' => [
"0" => 'a', "1" => 'b', "2" => 'c'
],
'result' => false,
],
[
'data' => [
'a', 'b', 'c'
],
'result' => false,
],
[
'data' => [],
'result' => false
],
];
}

/**
* Array is associative.
* @param array $data Data set.
* @param bool $result Return result after check.
*
* @return void
*
* @dataProvider providerTestIsAssociative
*/
public function testIsAssociative(array $data, $result)
{
$arr = new CArray();

if ($result === false) {
$message = 'Array type must be not associative';
$this->assertFalse(
$arr->isAssociative($data),
$message
);
} else {
$message = 'Array type must be associative';
$this->assertTrue(
$arr->isAssociative($data),
$message
);
}
}
}

0 comments on commit 88b5675

Please sign in to comment.