Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

FilesystemLoader and Testing #115

Open

Description

@DaveStein

I just swapped my templates from mustache to handlebars using this lib. I have a unit test to verify that given a certain file, it will return a certain output.

// Calls Handlebars loadTemplate and then render on the template
$output = $this->_templater->view( 'place', [ 'friend' => 'Person' ] );
$this->assertEquals( '<body><p></p>Hello Person</body>', $output );

I am using https://github.com/mikey179/vfsStream to mock the file system, but that doesn't work with this lib because of realpath being used in the constructor.

The directory comes in as vfs://mydir. You can see in this popular Mustache loader, how they handle it:
https://github.com/bobthecow/mustache.php/blob/master/src/Mustache/Loader/FilesystemLoader.php#L52

What do you think?

Activity

  1. DaveStein commented on May 15, 2015

    @DaveStein
    ContributorAuthor

    Alternatively the optional handling can go into one protected method while the directory checking goes into another, both of which would be called in constructor. Then people can extend to do custom behavior, such as accounting for vsf.

  2. fzerorubigd commented on May 15, 2015

    @fzerorubigd
    Contributor

    @DaveStein Thanks, I look into it if I get more spare time.
    And better if you can create a PR for this :)

  3. DaveStein commented on May 15, 2015

    @DaveStein
    ContributorAuthor

    @fzerorubigd which way do you like better? Accounting for :// inside or making it more extendable? Keep in mind to make it extendible I'd need to make $_baseDir protected rather than private.

  4. fzerorubigd commented on May 15, 2015

    @fzerorubigd
    Contributor

    @DaveStein using :// inside, is not good, changing the private field to protected is not a big deal. so I vote for the {more extendible} way.

  5. DaveStein commented on May 15, 2015

    @DaveStein
    ContributorAuthor

    kk I'll fork and make the change sometime between Sunday and Tuesday or so. I'll be away this weekend or I'd do it sooner :)

  6. JustBlackBird commented on May 15, 2015

    @JustBlackBird
    Contributor

    I believe supporting of custom stream wrappers (not only vfs://) could be useful in many cases not only for testing. For example they are used in Drupal 7 a lot. At the same time I don't like how the check is done in mustache.php. May be it's better to use something like stream_get_wrappers function.

    What do you think @fzerorubigd ?

  7. fzerorubigd commented on May 16, 2015

    @fzerorubigd
    Contributor

    @JustBlackBird I like the idea.

  8. DaveStein commented on May 18, 2015

    @DaveStein
    ContributorAuthor

    @JustBlackBird @fzeroubigd i got my PR for this here #117... maybe after that Just can add the streaming bit. My change makes things more extendable and then his makes things better on top of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions