Git Product home page Git Product logo

phpunit-json-assertions's Introduction

Hi, I'm Enrico ๐Ÿ‘‹

Twitter Follow LinkedIn Sponsor Blog

Over the years, I focused on helping software engineers to become more efficient by sharing knowledge and streamlining operational processes. I have created and contributed to many open-source projects over the past 20 years with this in mind.

Lately, I have been working on projects such as php-fpm_exporter, aws-rds-logs-s3-copier and k8s-image-swapper, to improve visibility, increase resiliency and reduce cost.

If you ๐Ÿ‘ค or your company ๐Ÿข have benefited from my work, then consider sponsoring me. Sponsoring helps me to help you to become more efficient. It allows me to continue writing bug fixes ๐Ÿ›, documentation ๐Ÿ“ and create new features ๐Ÿฆ„.

๐Ÿ‘ท Check out what I'm currently working on

๐ŸŒฑ My latest projects

๐Ÿ”ญ Latest releases I've contributed to

๐Ÿ“œ My recent blog posts

๐Ÿ““ Gists I wrote

phpunit-json-assertions's People

Contributors

davidfuhr avatar dependabot[bot] avatar estahn avatar j-t-mcc avatar mabiro avatar malgorzatawicha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

phpunit-json-assertions's Issues

Exception should be thrown when schema file is not found

Currently, if schema file is not found, Assert::assertJsonMatchesSchema() throws an exception JsonSchema\Exception\JsonDecodingException: Control character error, possibly incorrectly encoded. I took hours when I tried to understand what's wrong with schema file I passed instead of being aware of actual error immediately.

FileNotFoundException does not exist

Consider following simple test:

<?php
use PHPUnit\Framework\TestCase;
use EnricoStahn\JsonAssert\AssertClass;

class SimpleSchemaTest extends TestCase
{
    public function testSchema(): void
    {
        $request = [];
        $schemaFilePath = '';

        AssertClass::assertJsonMatchesSchema($request, $schemaFilePath);
    }
}

When I run this test I get following error:

Error : Class 'Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException' not found
  /home/ren/schema/vendor/estahn/phpunit-json-assertions/src/Assert.php:50
 /home/ren/schema/tests/SimpleSchemaTest.php:12

In Assert trait at line 50 a FileNotFoundException gets thrown. FileNotFoundException is an imported class. Fully qualified name is Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException. Since I don't have symfony/http-foundation installed the exception class cannot be found. In composer.json it is listed in require-dev section which is not getting installed by default.

"const" keyword not working

We use the test folder in the repository to test our jsonSchema. We have created a class based on the same structure as AssertTaitTest.php.
But when we want to test our json the keyword const doesn't work despite the errors put in the schema on purpose. However, the keyword enum works and is well taken into account in the errors.
You can find attached our test json and the associated schema.
Thanks in advance!

Our jsonSchema:
{ "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://<ourwebsite.fr/Schemas/ApiComponent/OuvragePush", "title": "Api Component Schema: Ouvrage Push", "type": "object", "properties": { "type": { "type": "string", "const": "OuvragePush"}, "price": { "type": "string", "const": "United States of America" } }, "required": [ "type", "price" ] }

Our mock json data:
'{ "type":"OuvragePushooo", "price": "14" }'

Provide more methods to validate JSON documents

  • query() - Queries the document and returns a result (shortcut/wrapper for \JmesPath\Env::search())
  • exists() - Returns boolean; TRUE when an element exists
  • assertExists() - exists() as a PHPUnit assert

compatibility with PHPUnit > 5

I don't know if this repository is still maintained.

If so, you may want to update for compatibility with PHPUnit ^6

\PHPUnit_Framework_Assert

to

\PHPUnit\Framework\Assert

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.